UIWebView 不保存 cookie

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

问题描述

我使用用户登录帐户的 UIWebView.用户可以使用 facebook 帐户登录.他是点击按钮 Facebook 并打开 UIWebView.登录后 UIWebView 关闭,用户可以使用您的个人帐户.但是当我关闭我的应用程序并再次打开它时,用户没有登录.UIWebView 不保存 cookie.我找到了这个答案 https://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 https://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];

但这对我没有帮助.

推荐答案

我遇到了这样的问题.我尝试了很多方法.我决定使用肮脏的黑客:D这就是我的方式:

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

当我为 facebook(或其他)获取 NSHTTPURLResponse 时,我将请求 url 保存到 NSUserDefaults:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)