美文网首页
UIWebview caches资源文件加载不能及时更新解决方案

UIWebview caches资源文件加载不能及时更新解决方案

作者: 某个胖子 | 来源:发表于2016-09-12 17:16 被阅读62次

问题描述:

使用webview加载本地轻应用,在app启动状态下,更新本地轻应用文件,用webview重新打开,但是依然显示更新前的效果。必须杀掉进程,用webview重新加载才能看到更新后的效果。

尝试过的方法

  • 生成request的时候禁止使用cache:
    [NSURLRequest requestWithURL:request.URL
    cachePolicy:NSURLRequestReloadIgnoringCacheData
    timeoutInterval:request.timeoutInterval];
  • 删除网络响应的缓存数据:
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
  • 修改NSUserDefaults中跟webview相关的设置
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    当然,以上方法都没有作用。

解决方法

后来在广大热心网友的帮助下,找到以下解决方法(文章链接)

Class webCache = NSClassFromString(@"WebCache");
SEL selector = NSSelectorFromString(@"setDisabled:");
[webCache performSelector:selector withObject:@YES];

相关文章

网友评论

      本文标题:UIWebview caches资源文件加载不能及时更新解决方案

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