Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing 'Not Now' when accepting app causes "com.facebook.sdk error2"

Using Facebook iOS SDK 3.1.

When choosing not to allow a 'Connect' to a Facebook app, I'm stuck with Facebook throwing "com.facebook.sdk error2." errors at me, even after re-installing my app.

Steps to reproduce:

  1. Choose to connect with Facebook
  2. Select 'Not Now' in the UIAlertView that pops up

=> I can't choose to connect again.

The only way for the user to connect again is to remove her Facebook account from Settings and add it again.

Is this a bug in the Facebook SDK or am I missing something?

I've obviously followed the authorization tutorial and everything works just fine (auth, posting stuff) when choosing to connect.

like image 468
Kristofer Sommestad Avatar asked Dec 21 '22 15:12

Kristofer Sommestad


1 Answers

OK, so I figured out what goes on here. When declining authorization of the app, this is stored as a setting on your device's Facebook account (Settings > Facebook).

By going to Settings and re-enabling the app in question, you can try to connect again. Not very clear to users, but you can catch this error and show some kind of info to the user.

This is how I implemented it (compared to Facebook's default error handling):

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState)state
                      error:(NSError *)error {
....

if (error) {
        NSString *errorTitle = NSLocalizedString(@"Error", @"Facebook connect");
        NSString *errorMessage = [error localizedDescription];
        if (error.code == FBErrorLoginFailedOrCancelled) {
            errorTitle = NSLocalizedString(@"Facebook Login Failed", @"Facebook Connect");
            errorMessage = NSLocalizedString(@"Make sure you've allowed My App to use Facebook in Settings > Facebook.", @"Facebook connect");
        }

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorTitle
                                                            message:errorMessage
                                                           delegate:nil
                                                  cancelButtonTitle:NSLocalizedString(@"OK", @"Facebook Connect")
                                                  otherButtonTitles:nil];
        [alertView show];
    }

}

like image 168
Kristofer Sommestad Avatar answered Apr 08 '23 20:04

Kristofer Sommestad