开发者

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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜