From 91f256424531030a454548693c3a6ca49ca3f35a Mon Sep 17 00:00:00 2001 From: Raghu Chandrasekaran Date: Wed, 3 Aug 2011 20:12:29 -0700 Subject: [PATCH] Refactor to init session delegate in Facebook.m constructor Summary: The change basically just sets the session delegate in the constructor so it's available when handleOpenUrl is called. Test Plan: Ran the DemoApp and ensured SSO still works. Reviewed By: toddkrabach Reviewers: seshadri, leon, atishm, toddkrabach, lshepard, caabernathy Differential Revision: 297414 Task ID: 653835 --- sample/DemoApp/Classes/DemoAppViewController.m | 7 ++++--- src/Facebook.h | 7 +++---- src/Facebook.m | 15 ++++++--------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/sample/DemoApp/Classes/DemoAppViewController.m b/sample/DemoApp/Classes/DemoAppViewController.m index 605a03f237..5bcbc06a5b 100644 --- a/sample/DemoApp/Classes/DemoAppViewController.m +++ b/sample/DemoApp/Classes/DemoAppViewController.m @@ -21,7 +21,7 @@ // Your Facebook APP Id must be set before running this example // See http://www.facebook.com/developers/createapp.php // Also, your application must bind to the fb[app_id]:// URL -// scheme (substitue [app_id] for your real Facebook app id). +// scheme (substitute [app_id] for your real Facebook app id). static NSString* kAppId = nil; @implementation DemoAppViewController @@ -45,6 +45,8 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { _permissions = [[NSArray arrayWithObjects: @"read_stream", @"publish_stream", @"offline_access",nil] retain]; + _facebook = [[Facebook alloc] initWithAppId:kAppId + andDelegate:self]; } return self; @@ -54,7 +56,6 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil * Set initial view */ - (void)viewDidLoad { - _facebook = [[Facebook alloc] initWithAppId:kAppId]; [self.label setText:@"Please log in"]; _getUserInfoButton.hidden = YES; _getPublicInfoButton.hidden = YES; @@ -86,7 +87,7 @@ - (void)dealloc { * Show the authorization dialog. */ - (void)login { - [_facebook authorize:_permissions delegate:self]; + [_facebook authorize:_permissions]; } /** diff --git a/src/Facebook.h b/src/Facebook.h index 9c391798b4..1ac8562bd1 100644 --- a/src/Facebook.h +++ b/src/Facebook.h @@ -42,13 +42,12 @@ @property(nonatomic, assign) id sessionDelegate; @property(nonatomic, copy) NSString* localAppId; -- (id)initWithAppId:(NSString *)app_id; +- (id)initWithAppId:(NSString *)appId + andDelegate:(id)delegate; -- (void)authorize:(NSArray *)permissions - delegate:(id)delegate; +- (void)authorize:(NSArray *)permissions; - (void)authorize:(NSArray *)permissions - delegate:(id)delegate localAppId:(NSString *)localAppId; - (BOOL)handleOpenURL:(NSURL *)url; diff --git a/src/Facebook.m b/src/Facebook.m index 23d8f5fc44..9591752ef4 100644 --- a/src/Facebook.m +++ b/src/Facebook.m @@ -57,11 +57,13 @@ @implementation Facebook /** * Initialize the Facebook object with application ID. */ -- (id)initWithAppId:(NSString *)app_id { +- (id)initWithAppId:(NSString *)appId + andDelegate:(id)delegate { self = [super init]; if (self) { [_appId release]; - _appId = [app_id copy]; + _appId = [appId copy]; + self.sessionDelegate = delegate; } return self; } @@ -209,10 +211,8 @@ - (NSDictionary*)parseURLParams:(NSString *)query { /////////////////////////////////////////////////////////////////////////////////////////////////// //public -- (void)authorize:(NSArray *)permissions - delegate:(id)delegate { +- (void)authorize:(NSArray *)permissions { [self authorize:permissions - delegate:delegate localAppId:nil]; } @@ -265,13 +265,10 @@ - (void)authorize:(NSArray *)permissions * and redirect the user to Safari. */ - (void)authorize:(NSArray *)permissions - delegate:(id)delegate localAppId:(NSString *)localAppId { self.localAppId = localAppId; self.permissions = permissions; - _sessionDelegate = delegate; - [self authorizeWithFBAppAuth:YES safariAuth:YES]; } @@ -370,7 +367,7 @@ - (BOOL)handleOpenURL:(NSURL *)url { */ - (void)logout:(id)delegate { - _sessionDelegate = delegate; + self.sessionDelegate = delegate; NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; [self requestWithMethodName:@"auth.expireSession"