我在我的iOS项目中使用FBConnect来授权用户(SSO)。
一旦登录,我有时需要打开一个Webview才能显示用户特定的对话框,如应用程序请求对话框(邀请到应用程序),甚至在我的应用程序用户浏览的Web视图中打开朋友的个人资料页面。
问题是Webview不会识别登录的用户,并要求他再次登录,这不是很友好。
任何想法如何共享登录的验证密钥/ cookie / webview的东西?
解决方案你可能会遇到这种情况。真的很沮丧。
Facebook iOS SDK不存储cookies用于访问
如果需要,您可以强制iOS库使用应用程序进行登录,并通过本地的UIWebview授权您的应用程序。因此,您将登录,并使用Cookie。您必须向现有的Facebook对象添加一个方法。通常,您调用:
- (void)authorize :( NSArray *)权限委托:(id< FBSessionDelegate> ;)委托授权,这反过来调用私有方法:
$ b $ (BOOL)tryFBAppAuth safariAuth:(BOOL)trySafariAuth,两个参数设置为YES。
您要添加一个调用同一私有的公共方法功能,但两个参数设置为NO。我将此方法添加到Facebook.m并在Facebook.h中声明,所以我可以调用它,但是我喜欢:
- ( void)authorize :( NSArray *)权限 tryFBApp:(BOOL)tryFBApp 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>)delegateto authorize, which in turns calls the private method:
- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth safariAuth:(BOOL)trySafariAuthwith 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登录,与网页视图分享?
发布评论