diff --git a/Example/Classes/TestViewController.m b/Example/Classes/TestViewController.m index 8970b2b..0ffacbd 100644 --- a/Example/Classes/TestViewController.m +++ b/Example/Classes/TestViewController.m @@ -106,7 +106,9 @@ - (void) twitterLoginViewController: (TwitterLoginViewController*) twitterLoginV - (void) twitterLoginViewController: (TwitterLoginViewController*) twitterLoginViewController didFailWithError: (NSError*) error { +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"twitterLoginViewController: %@ didFailWithError: %@", self, error); +#endif } #pragma mark - diff --git a/Example/Test.xcodeproj/project.pbxproj b/Example/Test.xcodeproj/project.pbxproj index 6c23b51..38e4df6 100644 --- a/Example/Test.xcodeproj/project.pbxproj +++ b/Example/Test.xcodeproj/project.pbxproj @@ -195,7 +195,14 @@ isa = PBXProject; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Test" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; projectDirPath = ""; projectRoot = ""; diff --git a/Sources/TwitterAuthenticator.h b/Sources/TwitterAuthenticator.h index 7ebea05..84e14da 100644 --- a/Sources/TwitterAuthenticator.h +++ b/Sources/TwitterAuthenticator.h @@ -36,17 +36,17 @@ TwitterConsumer* _consumer; NSString* _username; NSString* _password; - id _delegate; + id __unsafe_unretained _delegate; @private TwitterRequest* _twitterRequest; } -@property (nonatomic,retain) TwitterConsumer* consumer; +@property (nonatomic,strong) TwitterConsumer* consumer; -@property (nonatomic,retain) NSString* username; -@property (nonatomic,retain) NSString* password; +@property (nonatomic,strong) NSString* username; +@property (nonatomic,strong) NSString* password; -@property (nonatomic,assign) id delegate; +@property (nonatomic,unsafe_unretained) id delegate; - (void) authenticate; - (void) cancel; diff --git a/Sources/TwitterAuthenticator.m b/Sources/TwitterAuthenticator.m index 7ec1662..2fce721 100644 --- a/Sources/TwitterAuthenticator.m +++ b/Sources/TwitterAuthenticator.m @@ -41,27 +41,19 @@ - (id) init return self; } -- (void) dealloc -{ - [_twitterRequest release]; - [_consumer release]; - [_username release]; - [_password release]; - [super dealloc]; -} #pragma mark - - (NSString*) _formEncodeString: (NSString*) string { - NSString* encoded = (NSString*) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef) string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8); - return [encoded autorelease]; + NSString* encoded = (__bridge_transfer NSString*) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef) string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8); + return encoded; } - (NSString*) _formDecodeString: (NSString*) string { - NSString* decoded = (NSString*) CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, (CFStringRef) string, NULL); - return [decoded autorelease]; + NSString* decoded = (__bridge_transfer NSString*) CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef) string, NULL); + return decoded; } #pragma mark - @@ -91,7 +83,6 @@ - (void) authenticate - (void) cancel { if (_twitterRequest != nil) { - [_twitterRequest release]; _twitterRequest = nil; } } @@ -102,7 +93,6 @@ - (void) twitterRequest: (TwitterRequest*) request didFailWithError: (NSError*) { [_delegate twitterAuthenticator: self didFailWithError: error]; - [_twitterRequest release]; _twitterRequest = nil; } @@ -110,9 +100,9 @@ - (void) twitterRequest:(TwitterRequest *)request didFinishLoadingData: (NSData* { // Get the response data as a string - NSString* response = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]; + NSString* response = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; if (response == nil) { - response = [[[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding] autorelease]; + response = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding]; } if (response == nil) { @@ -141,7 +131,7 @@ - (void) twitterRequest:(TwitterRequest *)request didFinishLoadingData: (NSData* NSString* tokenSecret = [parameters valueForKey: @"oauth_token_secret"]; if (tokenValue != nil && tokenSecret != nil) { - TwitterToken* token = [[[TwitterToken alloc] initWithToken: tokenValue secret: tokenSecret] autorelease]; + TwitterToken* token = [[TwitterToken alloc] initWithToken: tokenValue secret: tokenSecret]; [_delegate twitterAuthenticator: self didSucceedWithToken: token]; } else { // TODO: Real error handling @@ -150,7 +140,6 @@ - (void) twitterRequest:(TwitterRequest *)request didFinishLoadingData: (NSData* // Release all our resources - [_twitterRequest release]; _twitterRequest = nil; } diff --git a/Sources/TwitterComposeViewController.m b/Sources/TwitterComposeViewController.m index 8a9282b..d46280d 100644 --- a/Sources/TwitterComposeViewController.m +++ b/Sources/TwitterComposeViewController.m @@ -120,8 +120,10 @@ - (void) _shortenLinks if (url != nil) { +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"Shortening link %@", [url absoluteString]); - +#endif + URLShortener* shortener = [[URLShortener new] autorelease]; if (shortener != nil) { @@ -156,8 +158,10 @@ - (IBAction) close { @try { [_delegate twitterComposeViewControllerDidCancel: self]; +#ifndef NS_BLOCK_ASSERTIONS } @catch (NSException* exception) { NSLog(@"TwitterComposeViewController caught an unexpected exception while calling the delegate: %@", exception); +#endif } } diff --git a/Sources/TwitterConsumer.h b/Sources/TwitterConsumer.h index cf1b3d9..81ad967 100644 --- a/Sources/TwitterConsumer.h +++ b/Sources/TwitterConsumer.h @@ -19,11 +19,7 @@ #import -@interface TwitterConsumer : NSObject { - @private - NSString* _key; - NSString* _secret; -} +@interface TwitterConsumer : NSObject @property (nonatomic,readonly) NSString* key; @property (nonatomic,readonly) NSString* secret; diff --git a/Sources/TwitterConsumer.m b/Sources/TwitterConsumer.m index 36f789a..af01787 100644 --- a/Sources/TwitterConsumer.m +++ b/Sources/TwitterConsumer.m @@ -28,17 +28,11 @@ @implementation TwitterConsumer - (id) initWithKey: (NSString*) key secret: (NSString*) secret { if ((self = [super init]) != nil) { - _key = [key retain]; - _secret = [secret retain]; + _key = key; + _secret = secret; } return self; } -- (void) dealloc -{ - [_key release]; - [_secret release]; - [super dealloc]; -} @end \ No newline at end of file diff --git a/Sources/TwitterLoginViewController.m b/Sources/TwitterLoginViewController.m index 764e9fe..fff8b8a 100644 --- a/Sources/TwitterLoginViewController.m +++ b/Sources/TwitterLoginViewController.m @@ -128,17 +128,21 @@ - (BOOL) textFieldShouldReturn: (UITextField*) textField if (textField == _usernameTextField) { [_passwordTextField becomeFirstResponder]; } - + +#ifndef NS_BLOCK_ASSERTIONS if (textField == _passwordTextField) { NSLog(@"Logging in"); } +#endif return YES; } - (void) updateLoginButton { +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"Yay"); +#endif self.navigationItem.rightBarButtonItem.enabled = ([_usernameTextField.text length] != 0 && [_passwordTextField.text length] != 0); } @@ -146,7 +150,9 @@ - (void) updateLoginButton - (void) twitterAuthenticator: (TwitterAuthenticator*) twitterAuthenticator didFailWithError: (NSError*) error; { +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"TwitterAuthenticatorViewController#twitterAuthenticator: %@ didFailWithError: %@", twitterAuthenticator, error); +#endif self.navigationItem.rightBarButtonItem.enabled = YES; [self _showLoginForm]; @@ -157,7 +163,9 @@ - (void) twitterAuthenticator: (TwitterAuthenticator*) twitterAuthenticator didF - (void) twitterAuthenticator: (TwitterAuthenticator*) twitterAuthenticator didSucceedWithToken: (TwitterToken*) token { +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"TwitterAuthenticatorViewController#twitterAuthenticator: %@ didSucceedWithToken: %@", twitterAuthenticator, token); +#endif self.navigationItem.rightBarButtonItem.enabled = YES; [self _showLoginForm]; diff --git a/Sources/TwitterRequest.h b/Sources/TwitterRequest.h index f003724..967190d 100644 --- a/Sources/TwitterRequest.h +++ b/Sources/TwitterRequest.h @@ -36,20 +36,20 @@ NSURL* _url; NSURL* _realm; NSString* _method; - id _delegate; + id __unsafe_unretained _delegate; @private NSURLConnection* _connection; NSMutableData* _data; NSInteger _statusCode; } -@property (nonatomic,retain) TwitterConsumer* twitterConsumer; -@property (nonatomic,retain) NSDictionary* parameters; -@property (nonatomic,retain) TwitterToken* token; -@property (nonatomic,retain) NSString* method; -@property (nonatomic,retain) NSURL* url; -@property (nonatomic,retain) NSURL* realm; -@property (nonatomic,assign) id delegate; +@property (nonatomic,strong) TwitterConsumer* twitterConsumer; +@property (nonatomic,strong) NSDictionary* parameters; +@property (nonatomic,strong) TwitterToken* token; +@property (nonatomic,strong) NSString* method; +@property (nonatomic,strong) NSURL* url; +@property (nonatomic,strong) NSURL* realm; +@property (nonatomic,unsafe_unretained) id delegate; - (void) execute; - (void) cancel; diff --git a/Sources/TwitterRequest.m b/Sources/TwitterRequest.m index bf94517..21fc9c3 100644 --- a/Sources/TwitterRequest.m +++ b/Sources/TwitterRequest.m @@ -44,16 +44,12 @@ - (id) init return self; } -- (void) dealloc -{ - [super dealloc]; -} #pragma mark - - (NSString*) _generateTimestamp { - return [NSString stringWithFormat: @"%d", time(NULL)]; + return [NSString stringWithFormat: @"%ld", time(NULL)]; } - (NSString*) _generateNonce @@ -62,18 +58,18 @@ - (NSString*) _generateNonce CFUUIDRef uuid = CFUUIDCreate(nil); if (uuid != NULL) { - nonce = (NSString*) CFUUIDCreateString(nil, uuid); + nonce = (__bridge_transfer NSString*) CFUUIDCreateString(nil, uuid); CFRelease(uuid); } - return [nonce autorelease]; + return nonce; } - (NSString*) _formEncodeString: (NSString*) string { - NSString* encoded = (NSString*) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, - (CFStringRef) string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8); - return [encoded autorelease]; + NSString* encoded = (__bridge_transfer NSString*) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, + (__bridge CFStringRef) string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8); + return encoded; } #pragma mark - @@ -115,16 +111,19 @@ - (void) execute [normalizedRequestParameters appendString: @"="]; [normalizedRequestParameters appendString: [self _formEncodeString: [parameters objectForKey: key]]]; } - +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"XXX normalizedRequestParameters = %@", normalizedRequestParameters); - +#endif + // Create the signature base string NSString* signatureBaseString = [NSString stringWithFormat: @"%@&%@&%@", _method, [self _formEncodeString: [NSString stringWithFormat: @"%@://%@%@", [_url scheme], [_url host], [_url path]]], [self _formEncodeString: normalizedRequestParameters]]; +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"XXX signatureBaseString = %@", signatureBaseString); +#endif // Create the secret @@ -136,8 +135,10 @@ - (void) execute secret = [NSString stringWithFormat:@"%@&", [self _formEncodeString: _twitterConsumer.secret]]; } +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"XXX Secret = %@", secret); - +#endif + // Set the signature parameter NSString* signatureString = [TwitterUtils encodeData: @@ -157,9 +158,11 @@ - (void) execute [normalizedRequestParameters appendString: @"="]; [normalizedRequestParameters appendString: [self _formEncodeString: [_parameters objectForKey: key]]]; } - + +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"XXX POST Data = %@", normalizedRequestParameters); - +#endif + NSData* requestData = [normalizedRequestParameters dataUsingEncoding: NSUTF8StringEncoding]; // Setup the Authorization header @@ -191,9 +194,11 @@ - (void) execute [authorization appendString: [self _formEncodeString: [authorizationParameters objectForKey: key]]]; [authorization appendString: @"\""]; } - + +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"Authorization: %@", authorization); - +#endif + // Setup the request and connection NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL: _url @@ -205,7 +210,7 @@ - (void) execute [request setValue: [NSString stringWithFormat: @"%d", [requestData length]] forHTTPHeaderField: @"Content-Length"]; [request setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"]; - _connection = [[NSURLConnection connectionWithRequest: request delegate: self] retain]; + _connection = [NSURLConnection connectionWithRequest: request delegate: self]; } } @@ -213,7 +218,6 @@ - (void) cancel { if (_connection != nil) { [_connection cancel]; - [_connection release]; _connection = nil; } } @@ -234,29 +238,27 @@ - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) { [_delegate twitterRequest: self didFailWithError: error]; - [_connection release]; _connection = nil; - [_data release]; _data = nil; } - (void) connectionDidFinishLoading: (NSURLConnection*) connection { if (_statusCode != 200) { +#ifndef NS_BLOCK_ASSERTIONS NSLog(@"Request failed with status code %d", _statusCode); - NSString* response = [[[NSString alloc] initWithData: _data encoding: NSUTF8StringEncoding] autorelease]; + NSString* response = [[NSString alloc] initWithData: _data encoding: NSUTF8StringEncoding]; NSLog(@"Response = %@", response); - // TODO: Real error handling - [_delegate twitterRequest: self didFailWithError: nil]; +#endif + // TODO: Add error message to userInfo? + [_delegate twitterRequest: self didFailWithError: [NSError errorWithDomain:@"TwitterRequestError" code:_statusCode userInfo:nil]]; } else { [_delegate twitterRequest: self didFinishLoadingData: _data]; } - [_connection release]; _connection = nil; - [_data release]; _data = nil; } diff --git a/Sources/TwitterToken.h b/Sources/TwitterToken.h index bbf68ea..0385245 100644 --- a/Sources/TwitterToken.h +++ b/Sources/TwitterToken.h @@ -25,8 +25,8 @@ NSString* _secret; } -@property (nonatomic,retain) NSString* token; -@property (nonatomic,retain) NSString* secret; +@property (nonatomic,strong) NSString* token; +@property (nonatomic,strong) NSString* secret; - (id) initWithToken: (NSString*) token secret: (NSString*) secret; diff --git a/Sources/TwitterToken.m b/Sources/TwitterToken.m index 91e6fb6..755278e 100644 --- a/Sources/TwitterToken.m +++ b/Sources/TwitterToken.m @@ -32,26 +32,20 @@ @implementation TwitterToken - (id) initWithToken: (NSString*) token secret: (NSString*) secret { if ((self = [super init]) != nil) { - _token = [token retain]; - _secret = [secret retain]; + _token = token; + _secret = secret; } return self; } -- (void) dealloc -{ - [_token release]; - [_secret release]; - [super dealloc]; -} #pragma mark - - (id) initWithCoder: (NSCoder*) coder { if ((self = [super init]) != nil) { - _token = [[coder decodeObjectForKey: @"token"] retain]; - _secret = [[coder decodeObjectForKey: @"secret"] retain]; + _token = [coder decodeObjectForKey: @"token"]; + _secret = [coder decodeObjectForKey: @"secret"]; } return self; } @@ -62,11 +56,4 @@ - (void) encodeWithCoder: (NSCoder*) coder [coder encodeObject: _secret forKey: @"secret"]; } -#pragma mark - - -- (NSString*) description -{ - return [NSString stringWithFormat: @"", self, _token, _secret]; -} - -@end \ No newline at end of file +@end diff --git a/Sources/TwitterTweetPoster.h b/Sources/TwitterTweetPoster.h index d59b827..d80213b 100644 --- a/Sources/TwitterTweetPoster.h +++ b/Sources/TwitterTweetPoster.h @@ -17,16 +17,16 @@ @private TwitterConsumer* _consumer; TwitterToken* _token; - id _delegate; + id __unsafe_unretained _delegate; NSString* _message; @private TwitterRequest* _request; } -@property (nonatomic,retain) TwitterConsumer* consumer; -@property (nonatomic,retain) TwitterToken* token; -@property (nonatomic,retain) id delegate; -@property (nonatomic,retain) NSString* message; +@property (nonatomic,strong) TwitterConsumer* consumer; +@property (nonatomic,strong) TwitterToken* token; +@property (nonatomic,unsafe_unretained) id delegate; +@property (nonatomic,strong) NSString* message; - (void) execute; - (void) cancel; diff --git a/Sources/TwitterTweetPoster.m b/Sources/TwitterTweetPoster.m index eae1eb4..18a63f8 100644 --- a/Sources/TwitterTweetPoster.m +++ b/Sources/TwitterTweetPoster.m @@ -21,12 +21,6 @@ - (id) init return self; } -- (void) dealloc -{ - [_request release]; - [_delegate release]; - [super dealloc]; -} #pragma mark - @@ -36,7 +30,7 @@ - (void) execute { _request = [TwitterRequest new]; if (_request != nil) { - _request.url = [NSURL URLWithString: @"http://api.twitter.com/1/statuses/update.xml"]; + _request.url = [NSURL URLWithString: @"https://api.twitter.com/1/statuses/update.xml"]; _request.twitterConsumer = _consumer; _request.token = _token; _request.method = @"POST"; @@ -51,7 +45,6 @@ - (void) cancel { if (_request != nil) { [_request cancel]; - [_request release]; _request = nil; } } @@ -68,4 +61,5 @@ - (void) twitterRequest:(TwitterRequest *)request didFinishLoadingData: (NSData* [_delegate twitterTweetPosterDidSucceed: self]; } -@end \ No newline at end of file +@end +