【问题标题】:NSFilemanager uploads new file, but UIWebView shows cached versionNSFilemanager 上传新文件,但 UIWebView 显示缓存版本
【发布时间】:2012-12-14 21:32:11
【问题描述】:

我正在构建的应用程序需要定期检查已知位置以获取更新的文件。它恰好是PDF。如果 x 时间已过,应用程序需要上传文件的新副本。以下代码 sn-p 有效。它下载文件。但该应用程序显示 PDF 的缓存版本而不是新版本。我通过查看应用程序包确认了这一点。这段代码运行后,Documents目录下肯定多了一个新文件。但是在捆绑包的 tmp/DiskImageCache-[random gibberish string] 中有一个旧版本 PDF 的副本 - 这就是我的 UIWebView 显示的内容。

我搜索了 NSFileManager 文档,当然,也掀起了一场风暴,但我无法找到一种方法让应用程序显示新上传的文件而不是 PDF 的缓存版本。

非常感谢您为解决此问题提供的任何帮助。

   -(void) checkFile:(NSString *)url andSaveTo:(NSString __autoreleasing *)filename {

    NSFileManager *manager = [NSFileManager defaultManager];
    NSError *error = nil;      
    NSDictionary *attributes = nil;

    if ([manager fileExistsAtPath:filename]) {

       attributes = [manager attributesOfItemAtPath:filename error:nil];

        double updateInterval = [[attributes fileCreationDate] timeIntervalSinceNow];
        cacheInterval = CacheInterval;

        if (ABS(updateInterval) > CacheInterval) {
         [self downloadFile:url andSaveTo:fileName];
        }
    }
}

【问题讨论】:

    标签: ios caching uiwebview nsfilemanager


    【解决方案1】:

    您始终可以通过将随机数作为参数附加到您的网址来阻止缓存

    例如:地址/yourfilehere.pdf?rand=0323094230948203984 并每次给你的长随机参数一个新的随机生成的数字

    【讨论】:

    • 地址/yourfilehere.pdf?rand=0323094230948203984 怎么样?因为 ?将被 %3F 替换。我有同样的问题,请帮忙。
    猜你喜欢
    • 2012-07-16
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    相关资源
    最近更新 更多