Permalink
Browse files

Make sure we initialize the login callback from fbDidLogin so it is s…

…till fired when loggin in from non-multitasking environments.
  • Loading branch information...
1 parent 88915f3 commit d148c578eb3e4bb9bb4e6fd7759641c8291f110f @dokterbob committed Aug 25, 2011
Showing with 22 additions and 21 deletions.
  1. +22 −21 native/ios/FacebookConnectPlugin.m
@@ -3,7 +3,8 @@
// GapFacebookConnect
//
// Created by Jesse MacFadyen on 11-04-22.
-// Copyright 2011 Nitobi. All rights reserved.
+// Updated by Mathijs de Bruin on 11-08-25.
+// Copyright 2011 Nitobi, Mathijs de Bruin. All rights reserved.
//
#import "FacebookConnectPlugin.h"
@@ -25,27 +26,13 @@ @implementation FacebookConnectPlugin
- (void) handleOpenURL:(NSNotification*)notification
{
NSURL* url = [notification object];
+
+ // What exactly does this check for?
if (![url isKindOfClass:[NSURL class]]) {
return;
}
- 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]];
-
-
- 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]];
- }
+ [facebook handleOpenURL:url];
}
- (void) init:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
@@ -91,7 +78,7 @@ - (void) login:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
NSMutableArray* marray = [NSMutableArray arrayWithArray:arguments];
[marray removeObjectAtIndex:0]; // first item is the callbackId
- // save the callbackId for handleOpenURL return (only works if the app is multi-tasked!)
+ // save the callbackId for the login callback
self.loginCallbackId = callbackId;
return [facebook authorize:marray];
@@ -138,8 +125,22 @@ - (void)fbDidLogin
{
// [facebook dialog:@"feed" andDelegate:self];
//[facebook requestWithGraphPath:@"me/friends" andDelegate:self];
- NSString* jsResult = [NSString stringWithFormat:@"FacebookGap.onLogin();"];
- [self.webView stringByEvaluatingJavaScriptFromString:jsResult];
+ // NSString* jsResult = [NSString stringWithFormat:@"FacebookGap.onLogin();"];
+
+ 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]];
+
+
+
+ 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]];
}

0 comments on commit d148c57

Please sign in to comment.