UIWebView不保存Cookie [英] UIWebView not save cookies

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

问题描述

我使用UIWebView用户登录帐户。用户可以使用Facebook帐号登录。他是点击按钮Facebook和打开UIWebView。登录UIWebView关闭后,用户可能会使用您的个人帐户。但是当我关闭我的应用程序,并再次打开用户没有登录。 UIWebView不保存Cookie。
我找到此答案 http://stackoverflow.com/a/26006163
并将此代码添加到我的应用程序。这只是暂时的。我关闭我的应用程序,并打开通过小时,它再次用户没有登录。
我尝试更改此行

I use UIWebView that users login in accounts. Users may login with facebook account. He is click button Facebook and opens UIWebView. After login UIWebView close and users may use your personal account. But when I close my app and open it again users not login. UIWebView not save cookies. I found this answer http://stackoverflow.com/a/26006163 And added this code in my app. This only works temporarily. I close my app and open through hours it again users not login. I tried to change this line

[cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];

到此

[cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:100*12*30*60*60] forKey:NSHTTPCookieExpires];

但它没有帮助我。

推荐答案

我有这样的问题。我试过很多方法。我决定使用dirty hack:D
这是我的方式:

I had such a problem. I tried many ways. I decided use dirty hack :D That's my way:

当我得到NSHTTPURLResponse的Facebook(或其他)我保存请求url到NSUserDefaults: p>

When I was getting NSHTTPURLResponse for facebook (or else) i save request url to NSUserDefaults:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
    if ([[httpResponse URL].absoluteString isEqualToString:@"http://www.simple.com/"])
    {
        [[NSUserDefaults standardUserDefaults] setURL:self.url forKey:@"urlLogin"];
        [self dismissViewController];
    }
}



当我打开我的应用程序时,使用NSURLRequest存储url:

And when I open my App i use NSURLRequest with my stored url:

NSURLRequest *request = [NSURLRequest requestWithURL:[[NSUserDefaults standardUserDefaults] URLForKey:@"urlLogin"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:3.0];
[NSURLConnection connectionWithRequest:request delegate:self];

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

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