Skip to content

Commit

Permalink
Refactor to init session delegate in Facebook.m constructor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
raghuc committed Aug 15, 2011
1 parent fc1cde2 commit 91f2564
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
7 changes: 4 additions & 3 deletions sample/DemoApp/Classes/DemoAppViewController.m
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -86,7 +87,7 @@ - (void)dealloc {
* Show the authorization dialog.
*/
- (void)login {
[_facebook authorize:_permissions delegate:self];
[_facebook authorize:_permissions];
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Facebook.h
Expand Up @@ -42,13 +42,12 @@
@property(nonatomic, assign) id<FBSessionDelegate> sessionDelegate;
@property(nonatomic, copy) NSString* localAppId;

- (id)initWithAppId:(NSString *)app_id;
- (id)initWithAppId:(NSString *)appId
andDelegate:(id<FBSessionDelegate>)delegate;

- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate;
- (void)authorize:(NSArray *)permissions;

- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate
localAppId:(NSString *)localAppId;

- (BOOL)handleOpenURL:(NSURL *)url;
Expand Down
15 changes: 6 additions & 9 deletions src/Facebook.m
Expand Up @@ -57,11 +57,13 @@ @implementation Facebook
/**
* Initialize the Facebook object with application ID.
*/
- (id)initWithAppId:(NSString *)app_id {
- (id)initWithAppId:(NSString *)appId
andDelegate:(id<FBSessionDelegate>)delegate {
self = [super init];
if (self) {
[_appId release];
_appId = [app_id copy];
_appId = [appId copy];
self.sessionDelegate = delegate;
}
return self;
}
Expand Down Expand Up @@ -209,10 +211,8 @@ - (NSDictionary*)parseURLParams:(NSString *)query {
///////////////////////////////////////////////////////////////////////////////////////////////////
//public

- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate {
- (void)authorize:(NSArray *)permissions {
[self authorize:permissions
delegate:delegate
localAppId:nil];
}

Expand Down Expand Up @@ -265,13 +265,10 @@ - (void)authorize:(NSArray *)permissions
* and redirect the user to Safari.
*/
- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate
localAppId:(NSString *)localAppId {
self.localAppId = localAppId;
self.permissions = permissions;

_sessionDelegate = delegate;

[self authorizeWithFBAppAuth:YES safariAuth:YES];
}

Expand Down Expand Up @@ -370,7 +367,7 @@ - (BOOL)handleOpenURL:(NSURL *)url {
*/
- (void)logout:(id<FBSessionDelegate>)delegate {

_sessionDelegate = delegate;
self.sessionDelegate = delegate;

NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
[self requestWithMethodName:@"auth.expireSession"
Expand Down

0 comments on commit 91f2564

Please sign in to comment.