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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

6 comments on commit 91f2564

@typeoneerror
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the documentation/README when you make a change in the API this significant would be very helpful. :D

@hhazen
Copy link

@hhazen hhazen commented on 91f2564 Aug 16, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raghuc
Copy link
Contributor Author

@raghuc raghuc commented on 91f2564 Aug 16, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@typeoneerror - my apologies, the update to the documentation is almost complete and will be available ASAP. Please feel free to contact me directly if there are any issues/questions that are blocking your development efforts and you need resolved urgently.

@echamberlain
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logout: should probably change too then. Otherwise, calling logout: will change the sessionDelegate.

@hhazen
Copy link

@hhazen hhazen commented on 91f2564 Aug 18, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sulkaharo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pulled the latest changes and am regretting it due to this API change, that wasn't mentioned anywhere. Didn't take too much reading of the sources / changeset to find out what to do to fix things, but the doc has been out of date for quite a while now...

Please sign in to comment.