美文网首页
iOS 清除cookies

iOS 清除cookies

作者: d4d5907268a9 | 来源:发表于2022-06-09 15:13 被阅读0次

    如果项目中使用了wkwebview,只用[[NSHTTPCookieStorage sharedHTTPCookieStorage] delete:cookie] 是不行的,要用[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:]

    +(void)clearCookie {
        // allWebsiteDataTypes清除所有缓存
    
        NSArray * types = @[WKWebsiteDataTypeCookies];
    
        NSSet*websiteDataTypes= [NSSetsetWithArray:types];
    
        NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
    
        [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
    
    
    
        }];
    
        //清除cookies
    
        NSHTTPCookie*cookie;
    
        NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    
        for(cookiein[storagecookies]){
    
            [storagedeleteCookie:cookie];
    
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS 清除cookies

          本文链接:https://www.haomeiwen.com/subject/ftemmrtx.html