码迷,mamicode.com
首页 > 移动开发 > 详细

iOS webView 设置cookie

时间:2017-06-22 18:33:19      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:type   global   obj   value   time   tpc   login   code   style   

 

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType中添加代码

    NSDictionary *dic = @{@"UserToken":[WCAppGlobal defaulAppGlobal].isLogin ? [self _getToken] : @""};
    [dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        // 设定 cookie
        NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:
                                [NSDictionary dictionaryWithObjectsAndKeys:
                                 [request.URL host], NSHTTPCookieDomain,
                                 [request.URL path], NSHTTPCookiePath,
                                 key,NSHTTPCookieName,
                                 obj,NSHTTPCookieValue,[[NSDate date] dateByAddingTimeInterval:60 * 60 * 24],NSHTTPCookieExpires,
                                 nil]];
        
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
    }];
 

 

iOS webView 设置cookie

标签:type   global   obj   value   time   tpc   login   code   style   

原文地址:http://www.cnblogs.com/sunyaxue/p/7066318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!