【问题标题】:Local HTML Cache policy in UIWebViewUIWebView 中的本地 HTML 缓存策略
【发布时间】:2015-07-27 07:26:07
【问题描述】:

我已经通过各种解决方案来清除 UIWebView 中的本地图像缓存,当我尝试在 html 中加载图像时,它会自动显示上一个图像(我使用相同的名称替换模板中的图像)。

[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL fileURLWithPath:[[CustomFunctions getFilesPath] stringByAppendingPathComponent:obj]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
[webview1 loadRequest:request];
[webview1 reload];

这是我的代码,任何人都可以建议我这样做。提前致谢。对不起我的英语。

【问题讨论】:

    标签: ios uiwebview nsurlrequest nsurlcache


    【解决方案1】:

    //防止应用程序内部网页缓存

    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];
    //[sharedCache release];
    sharedCache = nil;
    

    尝试使用它。它将清除应用程序的 url 缓存。

    【讨论】:

    • 使您的 webview 为零并再次初始化。
    【解决方案2】:

    试试这个……

    [[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest]; 
    

    这将删除特定请求的缓存响应。还有一个调用将删除 UIWebView 上运行的所有请求的所有缓存响应:

    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    

    【讨论】:

    • @iOSCreator 我已经发布了我的答案,请查看。
    猜你喜欢
    • 2010-10-06
    • 2010-10-26
    • 1970-01-01
    • 2012-09-05
    • 2020-08-03
    • 2011-11-12
    • 2011-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多