2

我需要删除 wkwebview 中的缓存。我正在使用下面的代码但没有成功。

 [[NSURLCache sharedURLCache]removeCachedResponseForRequest:request];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
4

2 回答 2

2
NSSet *dataTypes = [NSSet setWithArray:@[WKWebsiteDataTypeDiskCache,
                                         WKWebsiteDataTypeMemoryCache,
                                         ]];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:dataTypes
                                           modifiedSince:[NSDate dateWithTimeIntervalSince1970:0]
                                       completionHandler:^{
        }];
于 2017-05-15T02:21:26.940 回答
0

WKWebView 清除缓存 iOS 9.0 +

[[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:WKWebsiteDataStore.allWebsiteDataTypes completionHandler:^(NSArray<WKWebsiteDataRecord *> * _Nonnull records) {
    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:WKWebsiteDataStore.allWebsiteDataTypes forDataRecords:records completionHandler:^{
       CACHE_CLEARED_MSG;
    }];
}];
于 2020-06-05T06:16:01.940 回答