I've got an app that is nearing completion, and we've decided to allow users to login using Facebook.
At some point in the past, this feature was working, and now it simply hangs.
I've included the latest Parse SDK (1.6.1) and the latest Facebook SDK (3.21.1).
I think I've set up the app correctly. Here are the calls that I am making:
// AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Parse setApplicationId:@"appId" clientKey:@"clientKey"];
[PFFacebookUtils initializeFacebook];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[[PFFacebookUtils session] close];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:[PFFacebookUtils session]];
}
// Login View Controller
- (void)loginWithFacebok {
[PFFacebookUtils logInWithPermissions:@[@"public_profile", @"email"] block:^(PFUser *user, NSError *error) {
if (error != nil) {
// Error handling here.
} else {
if (user == nil) {
// Something odd happened; error handling here.
} else {
// A further Facebook method...
[self authorizeFacebookPublish];
}
}
}];
}
Basically, although it was working at a previous time, it's non-functional now in the sense that block
is never called. I do get the "app jump" to the Facebook app/web page (can't remember which now, and it "jumps" there and back too fast for me to tell, since I've approved this in the past). What's interesting is that if I force-quit the app (the app is basically in a "hung" state) and re-launch the app, the app loads and the user is logged in.
This is a fairly important point, but I can't find anyone else having this particular issue.
I saw this question, but we're not using Twitter.
This question isn't related to Parse.
EDIT: I was working through this more and kept being slightly confused by breakpoint catching. For instance, in my
-loginWithFacebook
method, I placed a breakpoint on the first line (the loginWithPermissions
call) and the first line of the returned block (if (error != nil) {...
, and the first breakpoint would be hit twice each time. I finally thought to try something new, so I added an NSLog
line above the first line and moved the first breakpoint there. Subsequent runs had the first breakpoint (now on NSLog
) hit once and then the first line of the block hit second. Therefore, I was able to determine that my problem is not, in fact, in my loginWithFacebook
method. It's in my authorizeFacebookPublish
method. Here's that code:
- (void)authorizeFacebookPublish {
NSLog(@"authorizing for Facebook publish..."); // First breakpoint here...
[PFFacebookUtils reauthorizeUser:[PFUser currentUser]
withPublishPermissions:@[@"publish_actions"]
audience:FBSessionDefaultAudienceFriends
block:^(BOOL succeeded, NSError *error) {
if (error != nil) { // Second breakpoint here...
// Error handling...
} else {
if (succeeded == YES) {
// Our app now has publishing permissions for the user
[PFUser currentUser][@"canPublishToFacebook"] = @(YES);
} else {
// Our app was refused publishing permissions
[PFUser currentUser][@"canPublishToFacebook"] = @(NO);
[[PFUser currentUser] saveInBackground];
}
// Log in was successful, so do other stuff....
}
}];
}
I'm now seeing the issue that's also listed here, which is that some breakpoint (apparently named "breakpoint 2.1" is being hit each time). This guy, however, isn't reporting the same problem I'm seeing, which is that the return block is never firing. Therefore, I am concluding that there is some problem in the authorization (or maybe re-authorization) block.
As I mentioned above, this code was working at some point in the past. Is it possible that "re-authorizing" causes an error? Is there a way for me to check whether the user has already authorized my app in the past and skip the authorization process (since it's already been done)? If that IS the problem, what's the correct procedure for logging a user back in after a logout (using Facebook)?