FBConnect登录,与网页视图分享? [英] FBConnect login, share with a webview?

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

问题描述

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



一旦登录,我有时需要打开一个Webview才能显示用户特定的对话框,如应用程序请求对话框(邀请到应用程序),甚至在我的应用程序用户浏览的Web视图中打开朋友的个人资料页面。



问题是Webview不会识别登录的用户,并要求他再次登录,这不是很友好。



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

解决方案

你可能会遇到这种情况。真的很沮丧。



Facebook iOS SDK不存储cookies用于访问



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

   - (void)authorize :( NSArray *)权限
委托:(id< FBSessionDelegate> ;)委托

授权,这反过来调用私有方法:

$ b $ (BOOL)tryF​​BAppAuth
safariAuth:(BOOL)trySafariAuth

,两个参数设置为YES。



您要添加一个调用同一私有的公共方法功能,但两个参数设置为NO。我将此方法添加到Facebook.m并在Facebook.h中声明,所以我可以调用它,但是我喜欢:

   - ( void)authorize :( NSArray *)权限
tryFBApp:(BOOL)tryF​​BApp
trySafariAuth:(BOOL)trySafariAuth
委托:(id< FBSessionDelegate>)委托{

[_permissions release];
_permissions = [权限保留];

_sessionDelegate = delegate;

[self authorizeWithFBAppAuth:tryFBApp safariAuth:trySafariAuth];
}

我将两个BOOL参数设置为NO,并且库弹出使用本地UIWebView,让我可以使用适用于该应用的Cookie。


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

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.

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

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 not storing cookies for access

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

with both parameters set to YES.

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

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登录,与网页视图分享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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