Skip to content

Commit

Permalink
Merge branch 'master' of github.com:davejohnson/phonegap-plugin-faceb…
Browse files Browse the repository at this point in the history
…ook-connect
  • Loading branch information
Dave Johnson committed Jul 12, 2011
2 parents 4d0c0e5 + 8f20b3a commit db43d88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion native/ios/FacebookConnectPlugin.h
Expand Up @@ -19,6 +19,6 @@
} }


@property (nonatomic, retain) Facebook *facebook; @property (nonatomic, retain) Facebook *facebook;

@property (nonatomic, copy) NSString* loginCallbackId;


@end @end
19 changes: 14 additions & 5 deletions native/ios/FacebookConnectPlugin.m
Expand Up @@ -19,7 +19,7 @@


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



NSDictionary* session = [NSDictionary NSDictionary* session = [NSDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:self.facebook.accessToken, [self.facebook.expirationDate description], APP_SECRET, [NSNumber numberWithBool:YES], @"...", @"...", nil] 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]]; 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];
NSString* callback = [result toSuccessCallbackString:self.loginCallbackId];
// we need to wrap the callback in a setTimeout(func, 0) so it doesn't block the UI (handleOpenURL limitation)
[super writeJavascript:[NSString stringWithFormat:@"setTimeout(function() { %@; }, 0);", callback]];
} }
} }


Expand Down Expand Up @@ -83,10 +91,11 @@ - (void) login:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
NSMutableArray* marray = [NSMutableArray arrayWithArray:arguments]; NSMutableArray* marray = [NSMutableArray arrayWithArray:arguments];
[marray removeObjectAtIndex:0]; // first item is the callbackId [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]; [super writeJavascript:jsString];
Expand Down

0 comments on commit db43d88

Please sign in to comment.