IOS登录IOS在模拟器上工作,但不在安装了本机应用程序的设备上 [英] Facebook login in IOS works on emulator but not on device with native app installed

查看:150
本文介绍了IOS登录IOS在模拟器上工作,但不在安装了本机应用程序的设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

面对以下问题:需要在IOS 7中执行Facebook登录。该模拟器正好在模拟器上运行,但在安装了本机应用程序的设备上运行时,会话无权执行登录。

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:

checarLogin方法的工作原理如下:

The checarLogin method works like:

我已经google搜索到它,并找出控制权限的设备设置在两种情况下,Facebook应用程序的工作方式不同:

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:

所以问题是:有另一种方式来处理在安装了本机Facebook应用的真实设备中登录,并使其接受权限而不需要更改iphone设置。

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?

推荐答案

这是我在应用程序中使用的,您必须允许登录界面。

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);
        }];

}

这就是你如何使用它

        [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

            }
        }];

这篇关于IOS登录IOS在模拟器上工作,但不在安装了本机应用程序的设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆