如何让UIWebView打开Facebook登录页面以响应iOS 5和iOS 6上的OAuth请求? [英] How can I get UIWebView to open Facebook login page in response to the OAuth request on iOS 5 and iOS 6?

查看:182
本文介绍了如何让UIWebView打开Facebook登录页面以响应iOS 5和iOS 6上的OAuth请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有:

(1)具有Facebook OAuth功能的Facebook API Web应用程序(FB Web应用程序)

(2) iPad上的UIWebView 浏览器(浏览器)

We have:
(1) Facebook API-based web application with Facebook OAuth functionality ("the FB web app")
(2) UIWebView-based browser on iPad ("the Browser")

我们的目标是打开Facebook登录页面登录FB网页在iPad上的基于UIWebView的浏览器(2)中的app(1)。

Our objective is to open the Facebook Login page to sign in to the FB web app (1) inside the UIWebView-based Browser (2) on iPad.

这里有一个类似的问题:

​​http: //facebook.stackoverflow.com/questions/11337285/no-longer-able-to-login-to-ios-app-via-oauth-the-page-requested-was-not-found

There is a somewhat similar issue here:
http://facebook.stackoverflow.com/questions/11337285/no-longer-able-to-login-to-ios-app-via-oauth-the-page-requested-was-not-found

但是,用户在Facebook表单中输入登录名和密码后,会出现该问题。我们的问题是我们无法首先显示Facebook的登录表单。将应用程序类型从Web更改为本机/桌面,如该问题中所建议的那样,没有帮助。

However, the issue of that question happens after the user enters login and password into the Facebook form. Our problem is that we cannot get the Facebook login form displayed in the first place. Changing the app type to from "Web" to "Native/Desktop", as suggested in that question, did not help.

步骤:

1.使用这个 UIWebView 浏览器打开我们的网页(简单的HTML页面)

2.点击此页面上的FB web app启动按钮< br>
3. OnClick JavaScript尝试启动OAuth,应打开Facebook的登录屏幕登录FB Web应用程序

Steps:
1. Open our web page (simple HTML page) with this UIWebView Browser
2. Click on "FB web app" launch button on this page
3. OnClick JavaScript tries to initiate OAuth, which should open the login screen of Facebook to sign in to the FB web app

当前结果(问题):

在iOS 5. +和iOS 6. +设备上

- 我们的网页保持不变

- Facebook登录页面未显示(我们的网站页面仍然显示)

在iOS 4.3(按预期工作):

- Facebook登录页面在相同的 UIWebView 浏览器的对象(替换我们的网页)

Current outcome (issue):
On iOS 5.+ and iOS 6.+ devices
- Our web page stays unchanged
- Facebook login page is NOT shown (our web page is still displayed)
On iOS 4.3 (works as expected):
- the Facebook login page is opened in the same UIWebView object of the Browser (replaces our web page)

预期结果:

- 显示Facebook登录页面,用户可以进入Facebook登录&密码

- 适用于iOS 5. +和iOS 6. +如果在iPad上的Safari浏览器中启动。 Facebook登录页面在单独的选项卡中打开(相反, UIWebView 中没有单独的选项卡)

Expected outcome:
- Facebook login page is displayed, and the user can enter Facebook login & password
- Works on iOS 5.+ and iOS 6.+ if launched in Safari browser on iPad. Facebook login page is opened in a separate tab (in contrast, there are no separate tabs in UIWebView)

问题:如何获取 UIWebView 打开Facebook登录页面以响应iOS 5+和iOS 6+上的OAuth请求?

Question: How can I get UIWebView to open Facebook login page in response to the OAuth request on iOS 5+ and iOS 6+?

更多技术细节:

我们记录不同的 NSURLRequest

-(BOOL)webView(UIWebView*)webView shouldStartLoadWithRequest(NSURLREquest*)request navigationType:…   

我们注意到正确和不正确行为的日志有一些差异。在这里执行流程如何寻找我:

And we notice some difference in logs for "correct" and "incorrect" behaviors. Here how execution flows look for me:

首先,我按FB Web App启动按钮启动OAuth,然后一些情况

Firstly, I press "FB Web App" launch button to initiate OAuth, then some cases go

iOS 4.3,正确

请求到www.facebook.com/dialog/oauth?...

请求到fbwebapp.com

请求m.facebook.com/login.php?...

--here facebook登陆出现

iOS 4.3, "correct"
request to www.facebook.com/dialog/oauth?...
request to fbwebapp.com
request to m.facebook.com/login.php?....
--here facebook login appears

iOS 5.0 ,incorrect1

请求到www.facebook.com/dialog/oauth?...

请求到fbwebapp.com

请求到m.facebook .com / login.php?...

iOS 5.0, "incorrect1"
request to www.facebook.com/dialog/oauth?...
request to fbwebapp.com
request to m.facebook.com/login.php?...

然后它可能是

- 很多m.facebook.com/login.php ?...与下一个...在参数中

后跟sqlite错误

- 现在我看到对不起,发生了错误页面(这是第一次)我遇到它)

Then it may be
--a lot of m.facebook.com/login.php?...with next… in parameters
followed by sqlite error
--right now I see "Sorry, something went wrong" page from facebook (it’s a first time at all I encounter it)

iOS 6.0wrong2

请求到www.facebook.com/dialog/oauth?...

请求到fbwebapp.com

iOS 6.0 "incorrect2"
request to www.facebook.com/dialog/oauth?...
request to fbwebapp.com

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)错误被调用,错误代码为-999

-(void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error is invoked with error code -999

你可以看到这个行为绝对取决于iOS版本。但常见的情况是,在获取m.facebook.com/login.php .. URL的步骤上发生错误。但这是我们可以检测到的。

You can see that behavior definitely depends on iOS version. But common case is that error happens on the step of obtaining m.facebook.com/login.php.. URL. But that’s all that we can detect.

我们正在为了整个一天寻找解决方案而敲响我们的头脑。

您可以帮助我们在 UIWebView 中打开Facebook登录页面以响应OAuth吗?

We’re banging our heads against that wall for the whole day looking for solutions. Hopelessly.
Can you help us get the Facebook Login page opened in the UIWebView in response to OAuth?

推荐答案

只需使用此代码

if (![FBSDKAccessToken currentAccessToken]) 
{   
    FBSDKLoginManager *manager = [[FBSDKLoginManager alloc]init];
    manager.loginBehavior = FBSDKLoginBehaviorWeb;
    [manager logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends"] handler:
     ^(FBSDKLoginManagerLoginResult *result, NSError *error) {

         NSLog(@"result.token: %@",result.token.tokenString);  
         NSLog(@"%@",result.token.userID);   
         NSLog(@"%hhd",result.isCancelled);     
     }];
}

//这里 manager.loginBehavior = FBSDKLoginBehaviorWeb; / code>是您需要在

这篇关于如何让UIWebView打开Facebook登录页面以响应iOS 5和iOS 6上的OAuth请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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