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

Support calling the successCallback of login() from handleOpenURL call #4

Merged
merged 1 commit into from
Jul 12, 2011
Merged
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: 1 addition & 1 deletion native/ios/FacebookConnectPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
}

@property (nonatomic, retain) Facebook *facebook;

@property (nonatomic, copy) NSString* loginCallbackId;

@end
17 changes: 12 additions & 5 deletions native/ios/FacebookConnectPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@implementation FacebookConnectPlugin

@synthesize facebook;
@synthesize facebook, loginCallbackId;

/* This overrides PGPlugin's method, which receives a notification when handleOpenURL is called on the main app delegate */
- (void) handleOpenURL:(NSNotification*)notification
Expand All @@ -32,11 +32,17 @@ - (void) handleOpenURL:(NSNotification*)notification
BOOL ok = [facebook handleOpenURL:url];
if (ok) {


NSDictionary* session = [NSDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:self.facebook.accessToken, [self.facebook.expirationDate description], APP_SECRET, [NSNumber numberWithBool:YES], @"...", @"...", nil]
forKeys:[NSArray arrayWithObjects:@"access_token", @"expires", @"secret", @"session_key", @"sig", @"uid", nil]];
NSDictionary* status = [NSDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:@"connected", session, nil]
forKeys:[NSArray arrayWithObjects:@"status", @"session", nil]];


[super writeJavascript:[NSString stringWithFormat:@"FB.Auth.setSession(%@);", [session JSONRepresentation]]];
PluginResult* result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsDictionary:status];
[super writeJavascript:[result toSuccessCallbackString:self.loginCallbackId]];
}
}

Expand Down Expand Up @@ -83,10 +89,11 @@ - (void) login:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
NSMutableArray* marray = [NSMutableArray arrayWithArray:arguments];
[marray removeObjectAtIndex:0]; // first item is the callbackId

[facebook authorize:marray delegate:self];
// save the callbackId for handleOpenURL return (only works if the app is multi-tasked!)
self.loginCallbackId = callbackId;

return [facebook authorize:marray delegate:self];

result = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString:@"Must call FB.init before FB.login"];
jsString = [result toErrorCallbackString:callbackId];
}

[super writeJavascript:jsString];
Expand Down