WebViewロードurl非更新クリアキャッシュiOS開発

1076 ワード

バックグラウンドでURLの内容を更新した後、アプリを削除せずに直接インストールを行った結果、ページの内容が更新されない場合があり、元のアプリを削除し、再パッケージした後、状況が回復し、自分が書いたwebviewがキャッシュをクリアする機能を追加していないのではないかと疑われ、以下はキャッシュをクリアするコードです.
- (void)leftBarButtonAction : (UIBarButtonItem *)sender {
    [self.baseButton removeFromSuperview];
    _baseWebView = nil;
    [self cleanCacheAndCookie];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)cleanCacheAndCookie{
    //  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];
} 

またはロード時にキャッシュを直接禁止する
request = [NSURLRequest requestWithURL:url  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];