使用UIWebView将cookie发送到URL时出现问题

时间:2017-02-07 05:16:52

标签: ios objective-c cookies uiwebview nshttpcookie

我必须使用URLUIWebview中打开cookie。我必须向cookie发送UIWebView。只有当cookie值正确时才会加载webview

这是我的设置:

在我的appDelegate方法

 - (void)applicationDidBecomeActive:(UIApplication *)application 
  {
      [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

   }

这是我在cookie ViewController's方法中创建viewDidLoad和加载请求的方式:

//Set Cookie
NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"username" forKey:NSHTTPCookieName];
[cookieProperties setObject:cookieValue forKey:NSHTTPCookieValue];
[cookieProperties setObject:@".xyz.com" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];

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

NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];

//Create Reqeust
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:completeURL]];

[_webView loadRequest:request];

问题我正面临

它只适用于我的模拟器。我在设备和其他Mac上进行了测试,但它无法正常工作。有时它甚至不适用于我的系统。

我无法找到背后的原因是什么?

0 个答案:

没有答案