How to get native Facebook login on iOS using SDK

2019-04-10 14:39发布

I downloaded the new Facebook iOS SDK 3.1, which promises to have a native login prompt. I ran their sample login app on my iOS 6 device. When I attempted to connect with Facebook, I did not get a native login. Instead, the Facebook app launched - same as the old SDK. Their Facebook login button basically does this:

[appDelegate.session 
    openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
        [self updateView];
    }
];

I thought maybe the sample code isn't calling the right function. So I tried FBSession's other login function.

[appDelegate.session 
    openWithBehavior:FBSessionLoginBehaviorWithNoFallbackToWebView 
    completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
        [self updateView];
    }
];

I tried all possible behaviours and none of them popped up the native login prompt.

3条回答
你好瞎i
2楼-- · 2019-04-10 14:41

Read this: https://developers.facebook.com/docs/howtos/ios-6/#nativeauthdialog

Basically you must request basic permissions and read permissions first and then request publish permissions separately.

查看更多
等我变得足够好
3楼-- · 2019-04-10 14:43

Did you log into Facebook from the iOS settings first?

Once you do that, their example project Scrumptious will use the native login prompt when you try to connect.

查看更多
Rolldiameter
4楼-- · 2019-04-10 14:46

This is by design, and described in the second section of https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/upgrading-from-3.0/

Basically, you are not able to ask for both read and publish permissions with the iOS6 dialog. Therefore you are more-or-less required to ask for them in a staggered way (e.g. read on first login, and then publish when your app actually needs to publish).

If you insist on using the deprecated method to try and get read & publish at the same time, the SDK has no choice but to return to the web or app-switched technique.

查看更多
登录 后发表回答