Facebook SDK 3.1 iOS: Handle login if user remove app from Facebook Settings

后端 未结 3 1843
执笔经年
执笔经年 2021-01-31 12:08

I want to put some Facebook integration in my app. At this point I\'ve managed to login, post to friends wall, retrieve the list of friends, etc. Everything is OK except for one

3条回答
  •  自闭症患者
    2021-01-31 13:03

    I have the same problem and could not find proper documentation about error codes on Facebook SDK site.

    I solved problem by comparing the [error code]; or [error userInfo]; value.

    Your session will have the state FBSessionStateClosedLoginFailed and userInfo dictionary of error will have the following form

    "com.facebook.sdk:ErrorLoginFailedReason" = "com.facebook.sdk:ErrorLoginFailedReason";
    

    On the other hand error code shows me 2 so that you can handle it at the end of sessionStateChanged::: function

    - (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState)state
                      error:(NSError *)error {
    switch (state) {
        case FBSessionStateOpen: {
            //update permissionsArrat
            [self retrieveUSerPermissions];
    
            if (!needstoReopenOldSession) {
                //First User information
                [self getUserInformation:nil];
            }
    
            NSNotification *authorizationNotification = [NSNotification notificationWithName:facebookAuthorizationNotification object:nil];
            [[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];
    
        }
        case FBSessionStateClosed: {
            break;
        }
        case FBSessionStateClosedLoginFailed: {
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        }
        default:
            break;
    }
    
    if (error) 
    {
        NSNotification *authorizationNotification = [NSNotification  notificationWithName:faceBookErrorOccuredNotification object:error];
        [[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];
    }
    }
    

提交回复
热议问题