Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@shazron

Support calling the successCallback of login() from handleOpenURL call (after UI login from Mobile Safari/Facebook app).

NOTE: this only works if the PhoneGap app supports multi-tasking. Also, the FB.Login callback must NOT call any interactive UI like alert()

@shazron shazron Support calling the successCallback of login() from handleOpenURL cal…
…l (after UI login from Mobile Safari/Facebook app). Note: this only works if the PhoneGap app supports multi-tasking. Also, the FB.Login callback must NOT call any interactive UI like alert()
cf2a115
@davejohnson davejohnson merged commit 3753776 into Wizcorp:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 12, 2011
  1. @shazron

    Support calling the successCallback of login() from handleOpenURL cal…

    shazron authored
    …l (after UI login from Mobile Safari/Facebook app). Note: this only works if the PhoneGap app supports multi-tasking. Also, the FB.Login callback must NOT call any interactive UI like alert()
This page is out of date. Refresh to see the latest.
View
2  native/ios/FacebookConnectPlugin.h
@@ -19,6 +19,6 @@
}
@property (nonatomic, retain) Facebook *facebook;
-
+@property (nonatomic, copy) NSString* loginCallbackId;
@end
View
17 native/ios/FacebookConnectPlugin.m
@@ -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
@@ -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]];
}
}
@@ -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];
Something went wrong with that request. Please try again.