FBConnect 登录,与 webview 共享? [英] FBConnect login, share with a webview?

查看:13
本文介绍了FBConnect 登录,与 webview 共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 iOS 项目中使用 FBConnect 来授权用户 (SSO).

I am using FBConnect in my iOS project to authorize the user (SSO).

登录后,我有时需要打开 Webview 以显示用户特定的对话框,例如应用请求对话框(邀请应用),甚至需要在 webview 中打开朋友的个人资料页面以供我的应用用户浏览.

Once logged in, I sometimes need to open a Webview in order to show the user specific dialogs such as the app request dialog (invite to app) and even to open a friend's profile page in a webview for my app user to browse.

问题是Webview无法识别登录的用户并要求他重新登录,这不是很友好.

The problem is that the Webview doesn't recognize the logged in user and asks him to login again, this is not very friendly.

任何想法如何与 webview 共享登录的身份验证密钥/cookie/东西?

Any ideas how to share the logged in auth key/cookie/something with the webview?

推荐答案

您可能会遇到这种情况.真的很郁闷.

You are likely running into this situation. It's really frustrating.

Facebook iOS SDK 不为访问

如果需要,您可以强制 iOS 库使用您的应用进行登录,并通过应用本地的 UIWebview 进行授权.您因此已登录,并可以使用 cookie.您必须向现有 Facebook 对象添加一个方法.通常,您调用:

You can, if you want, force the iOS library to use your app for login, and authorize through a UIWebview local to your app. You are thus logged in, and have cookies to use. You'll have to add a method to the existing Facebook object. Normally, you call:

- (void) authorize:(NSArray *)permissions 
          delegate:(id<FBSessionDelegate>)delegate

授权,它依次调用私有方法:

to authorize, which in turns calls the private method:

- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
                    safariAuth:(BOOL)trySafariAuth

两个参数都设置为 YES.

with both parameters set to YES.

您想添加一个公共方法,该方法调用相同的私有函数,但两个参数都设置为 NO.我将此方法添加到 Facebook.m 并在 Facebook.h 中声明它以便我可以随意调用它:

You want to add a public method that calls the same private function but with both parameters set to NO. I added this method to Facebook.m and declared it in Facebook.h so I could call it however I like:

- (void)authorize:(NSArray *)permissions 
         tryFBApp:(BOOL) tryFBApp 
    trySafariAuth:(BOOL) trySafariAuth
         delegate:(id<FBSessionDelegate>)delegate {

    [_permissions release];
    _permissions = [permissions retain];

    _sessionDelegate = delegate;

    [self authorizeWithFBAppAuth:tryFBApp safariAuth:trySafariAuth];
}

我将两个 BOOL 参数设置为 NO 调用它,库会弹出一个本地 UIWebView,为我留下适用于该应用程序的 cookie.

I call that with the two BOOL parameters set to NO, and the library pops ups a local UIWebView that leaves me with cookies that work for the app.

这篇关于FBConnect 登录,与 webview 共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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