Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log via NSLog only when debugging #7

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Example/Classes/TestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
7 changes: 7 additions & 0 deletions Example/Test.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
10 changes: 5 additions & 5 deletions Sources/TwitterAuthenticator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
TwitterConsumer* _consumer;
NSString* _username;
NSString* _password;
id<TwitterAuthenticatorDelegate> _delegate;
id<TwitterAuthenticatorDelegate> __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<TwitterAuthenticatorDelegate> delegate;
@property (nonatomic,unsafe_unretained) id<TwitterAuthenticatorDelegate> delegate;

- (void) authenticate;
- (void) cancel;
Expand Down
25 changes: 7 additions & 18 deletions Sources/TwitterAuthenticator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down Expand Up @@ -91,7 +83,6 @@ - (void) authenticate
- (void) cancel
{
if (_twitterRequest != nil) {
[_twitterRequest release];
_twitterRequest = nil;
}
}
Expand All @@ -102,17 +93,16 @@ - (void) twitterRequest: (TwitterRequest*) request didFailWithError: (NSError*)
{
[_delegate twitterAuthenticator: self didFailWithError: error];

[_twitterRequest release];
_twitterRequest = nil;
}

- (void) twitterRequest:(TwitterRequest *)request didFinishLoadingData: (NSData*) data
{
// 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) {
Expand Down Expand Up @@ -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
Expand All @@ -150,7 +140,6 @@ - (void) twitterRequest:(TwitterRequest *)request didFinishLoadingData: (NSData*

// Release all our resources

[_twitterRequest release];
_twitterRequest = nil;
}

Expand Down
6 changes: 5 additions & 1 deletion Sources/TwitterComposeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
}
}

Expand Down
6 changes: 1 addition & 5 deletions Sources/TwitterConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

#import <Foundation/Foundation.h>

@interface TwitterConsumer : NSObject {
@private
NSString* _key;
NSString* _secret;
}
@interface TwitterConsumer : NSObject

@property (nonatomic,readonly) NSString* key;
@property (nonatomic,readonly) NSString* secret;
Expand Down
10 changes: 2 additions & 8 deletions Sources/TwitterConsumer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion Sources/TwitterLoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,31 @@ - (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);
}

#pragma mark -

- (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];
Expand All @@ -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];
Expand Down
16 changes: 8 additions & 8 deletions Sources/TwitterRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@
NSURL* _url;
NSURL* _realm;
NSString* _method;
id<TwitterRequestDelegate> _delegate;
id<TwitterRequestDelegate> __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<TwitterRequestDelegate> 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<TwitterRequestDelegate> delegate;

- (void) execute;
- (void) cancel;
Expand Down
Loading