天天看点

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];