Facebook login in IOS works on emulator but not on device with native app installed

孤街浪徒 提交于 2019-12-08 01:16:38

问题


Facing the following problem: need to perform Facebook login in IOS 7. The thing goes right on the emulator but when running it on device with native app installed, the session give not permission to perform the login.

Using the code to create session:

The checarLogin method works like:

I have googled to find it and figured out that the device settings that control the permissions of Facebook app works differently in the two cases:

Emulator give the permission with no issues:

The following image was took from emulator too, but only to illustrate the way the device works by default:

So the question is: there is other way to handle the login when running in a real device with native Facebook app installed and make it accept the permissions without the need to change the iphone settings?


回答1:


This is what I use in my apps, you have to allow the login UI.

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI completionHandler:(FBSessionStateHandler)handler {

// We pass this permissions array into our request.
// I only request email, but there are many more options.
//
NSArray *permissions = @[@"email", @"basic_info"];

return [FBSession
        openActiveSessionWithReadPermissions:permissions
        allowLoginUI:allowLoginUI
        completionHandler:^(FBSession *session,
                            FBSessionState state,
                            NSError *error) {

            if (handler)
                handler(session, state, error);
        }];

}

And that's how you use it

        [self openSessionWithAllowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {

            if (!error && status == FBSessionStateOpen) {
                NSString *token = session.accessTokenData.accessToken;

                // You're logged in!

            } else {

                // Something wrong happened

            }
        }];



回答2:


I faced a similar problem, and this is what worked for me:

https://stackoverflow.com/a/12069251/2407717

A colleague changed some of our project settings, including the Bundle Identifier, so it wasn't matching the iOS Bundle ID on Facebook anymore.



来源:https://stackoverflow.com/questions/21632043/facebook-login-in-ios-works-on-emulator-but-not-on-device-with-native-app-instal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!