iOS 清除webView缓存

//清除cookies

    NSHTTPCookie *cookie;

    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

    for (cookie in [storage cookies]){

        [storage deleteCookie:cookie];

    }

    //清除UIWebView的缓存

    [[NSURLCache sharedURLCache] removeAllCachedResponses];

    NSURLCache * cache = [NSURLCache sharedURLCache];

    [cache removeAllCachedResponses];

    [cache setDiskCapacity:0];

    [cache setMemoryCapacity:0];

    

    NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *cookiesFolderPath = [libraryPath stringByAppendingString:@"/Cookies"];

    NSError *errors;

    [[NSFileManager defaultManager] removeItemAtPath:cookiesFolderPath error:&errors];


版权声明:本文为lfl18326162160原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。