Facebook iOS SDK不存储访问Cookie [英] Facebook iOS SDK not storing cookies for access

查看:94
本文介绍了Facebook iOS SDK不存储访问Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个很奇怪的错误。登录时,Facebook对象不是在设备上存储safari上的任何cookie,而是在模拟器上。我如何知道?

  NSHTTPCookie * cookie; 
NSHTTPCookieStorage * storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for(cookie in [storage cookies])
{
NSString * domainName = [cookie domain];
NSLog(domainName);
NSRange domainRange = [domainName rangeOfString:@facebook];
if(domainRange.length> 0)
{
[storage deleteCookie:cookie];
}
}

在Simulator上运行时,我可以看到两个cookie的名字。我在设备上得到零。这是发生甚至与Facebook的DemoApp。
我不知道这是从哪里来的,所以我真的不知道我可以提供什么信息,以使帖子更完整。请,请现在我失踪了。代码只是来自DemoApp,我没有改变/添加/删除任何东西。



谢谢。



请记住,每个iOS应用程式都有独立的储存空间 - 他们保持这种方式,以便另一个应用程序不能触摸不属于它的东西。这个沙箱防止恶意或恶意应用程式伤害自己以外的任何东西。



这是iPhone上的Safari的真实情况 - Cookie在Safari中设置的会话不可用您的应用程式。 Safari中的UIWebView中设置的Cookie不可用。有一些混乱,因为在桌面OSX系统,你可以共享cookie。你不能在iOS上这样做,尽管类方法的诱人名称SharedHTTPCookieStorage。



Facebook SDK身份验证代码可以尝试三种方式在设备上进行身份验证。它可以调用Facebook应用程序,并要求通过它进行身份验证,允许该应用程序的用户只能登录一次。如果未安装FB应用程序,它会在移动safari浏览器中打开一个窗口,并尝试在那里登录,如果可以,在浏览器的沙箱中设置Cookie。如果它可以打开,它会打开一个UIWebView在你的应用程序的空间,并将其本地cookie存储到你的应用程序。



我猜猜认证发生在不同的地方你的模拟器和你的iPhone上,所以cookie生活在别的地方。



真正令人沮丧的是,如果你利用好的单点登录功能,你不能打开UIWebviews到您的应用程序的Facebook,而不强制第二次登录。您无法使用这些Cookie。


This is a really weird error. When login, the facebook object is not storing any cookies on safari on the device, but it does on the simulator. How do I know?

NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
    NSString* domainName = [cookie domain];
    NSLog(domainName);
    NSRange domainRange = [domainName rangeOfString:@"facebook"];
    if(domainRange.length > 0)
    {
        [storage deleteCookie:cookie];
    }
} 

While running on Simulator I can see two cookie's name. I get zero on the device. This is happening even with the DemoApp from facebook. I don't have a clue about where is this coming from, so I really don't know what info could I provide in order to make the post more complete. Please, request me anything I'm missing now. The code is just from the DemoApp, I haven't changed/added/removed anything.

Thanks.

解决方案

You may be running into an odd thing with the iOS library.

Remember that every iOS app has separate storage space - they are kept that way so that another app can't touch things that do not belong to it. This sandboxing prevents malicious or badly made apps from hurting anything other than themselves.

This is true for Safari on the iPhone - cookies set for a session in Safari ARE NOT available to your app. Cookies set in a UIWebView in your app ARE NOT available to Safari. There is some confusion about this since on the desktop OSX system, you can share cookies. You can not do so on iOS, despite the class method's tempting name, SharedHTTPCookieStorage.

The Facebook SDK authentication code can try up to three ways to authenticate on a device... It can call the Facebook app, and ask to authenticate through it, allowing users of that app to only log in once. If the FB app is not installed, it opens a window in the mobile safari browser and tries to login there, setting cookies in the browser's sandbox if it can. If it can open neither, it opens a UIWebView in your app's space and stores its cookies local to your app.

I would guess that the authentication is happening in different places in your simulator and on your iPhone, and so the cookies live somewhere else.

What is really frustrating is that if you utilize the nice single sign on feature, you cannot then open UIWebviews to Facebook in your app without forcing a second logon. The cookies are not available to you.

这篇关于Facebook iOS SDK不存储访问Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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