Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

ios - Native Facebook Login stopped working after SDK update to 3.14

Update: Somehow the behaviour seems to have changed. I don't get the error message any more but the native login still does not work. Instead I am redirected to the web dialog if the Facebook app is not installed. Did Facebook remove the native login support for the last SDK? The permissions I request were "public_profile", "email" and "user_likes". I also tried removing the "user_likes" permission, as it is not part of the basic permissions as stated here: https://developers.facebook.com/docs/ios/ui-controls#iosintegration Still the native login dialog does not appear!

I recently updated my iOS Project to use the Facebook SDK version 3.14.0 (upgraded from 3.13.0 via CocoaPods). I read the upgrade notes and changed the permission "basic_info" to "public_profile" as recommended.

If I now call

FBSession openActiveSessionWithReadPermissions:
                                   allowLoginUI:
                              completionHandler:

it only works via the web or Facebook App login. If I login natively in the OS settings, the login fails with

Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)"

Has anyone experienced similar problems? Doesn't the native login work anymore this way? Or is it a problem with the "changed" permissions?

Regards K

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just ran to this issue also, here's the details on what has happened & how I fixed my app.

Bottom line
Due to the new login process wherein users can now approve / deny each requested permission (something not supported by the native ios integrated login), Facebook has changed the sdk's default login behavior to first try the Facebook fast app switch & then fall back on the web view, completely ignoring any ios system level Facebook credentials.

This is noted in the upgrade guide (form 3.13 > 3.14) here: https://developers.facebook.com/docs/ios/upgrading

Relevant portion:
"The default login behavior has changed from FBSessionLoginBehaviorUseSystemAccountIfPresent to FBSessionLoginBehaviorWithFallbackToWebView."

So what to do?
Well, if you don't need any of the new things, FBLikeControl etc..., that were introduced in 3.14, you could just downgrade to 3.13. However, if you want/need to use 3.14n there's an instance method on FBSession that takes the FBSessionLoginBehavior as a parameter: https://developers.facebook.com/docs/reference/ios/current/class/FBSession/#openWithBehavior:completionHandler:

I updated the body of my method for opening a Facebook session from:

    [FBSession openActiveSessionWithReadPermissions:@[@"email", @"user_location"]
                                       allowLoginUI:YES
                                  completionHandler:
                                          ^(FBSession *session, FBSessionState state, NSError *error) {
                                              [self sessionStateChanged:session state:state error:error];
                                          }
    ];

to:

    FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error) {
        [self sessionStateChanged:session state:status error:error];
    };

    if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded) {
        // we have a cached token, so open the session
        [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
                  completionHandler:completionHandler];
    } else {
        [self clearAllUserInfo];
        // create a new facebook session
        FBSession *fbSession = [[FBSession alloc] initWithPermissions:@[@"email", @"user_location"]];
        [FBSession setActiveSession:fbSession];
        [fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
                  completionHandler:completionHandler];
    }

NOTE: my clearAllUserInfo method includes the following lines:

    [FBSession.activeSession closeAndClearTokenInformation];
    [FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {
        NSLog(@"%@", error);
    }];
    [FBSession setActiveSession:nil];

It's also worth checking out the Facebook documentation on understanding sessions: http://developers.facebook.com/docs/facebook-login/ios/v2.0#sessions


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...