简体   繁体   English

Facebook iOS SDK不存储cookie以便访问

[英]Facebook iOS SDK not storing cookies for access

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. 登录时,facebook对象不会在设备上的safari上存储任何cookie,但会在模拟器上存储。 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. 在模拟器上运行时,我可以看到两个cookie的名称。 I get zero on the device. 我在设备上得到零。 This is happening even with the DemoApp from facebook. 即使使用Facebook的DemoApp,这种情况也会发生。 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. 该代码仅来自DemoApp,我没有更改/添加/删除任何内容。

Thanks. 谢谢。

You may be running into an odd thing with the iOS library. iOS库可能会让您感到奇怪。

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. 请记住,每个iOS应用程序都有单独的存储空间-它们以这种方式保留,以使另一个应用程序无法触摸不属于它的东西。 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. 这对于iPhone上的Safari来说是正确的-为Safari中的会话设置的Cookie不适用于您的应用。 Cookies set in a UIWebView in your app ARE NOT available to Safari. 在您的应用程序的UIWebView中设置的Cookie不适用于Safari。 There is some confusion about this since on the desktop OSX system, you can share cookies. 由于在桌面OSX系统上可以共享cookie,因此对此有些困惑。 You can not do so on iOS, despite the class method's tempting name, SharedHTTPCookieStorage. 尽管类方法具有诱人的名称SharedHTTPCookieStorage,但您无法在iOS上这样做。

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. Facebook SDK身份验证代码最多可以尝试三种在设备上进行身份验证的方法...它可以调用Facebook应用程序,并要求通过它进行身份验证,从而使该应用程序的用户只能登录一次。 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. 如果未安装FB应用程序,它将在移动safari浏览器中打开一个窗口,然后尝试登录该窗口,并在浏览器的沙箱中设置cookie。 If it can open neither, it opens a UIWebView in your app's space and stores its cookies local to your app. 如果无法打开,则在应用程序空间中打开UIWebView并将其cookie存储在应用程序本地。

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. 我猜想身份验证是在模拟器和iPhone的不同位置进行的,因此cookie驻留在其他地方。

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. 真正令人沮丧的是,如果您利用漂亮的单点登录功能,则无法在不强制第二次登录的情况下在应用程序中打开UIWebviews到Facebook中。 The cookies are not available to you. Cookies对您不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM