iOS中的UIWebViewcaching

我在我的应用程序托pipeUIWebView 。 它看起来像UIWebViewcaching图像和数据本身。 我想清除应用程序启动时的caching。

清理Safari的caching没有帮助。 我发现刷新UIWebView的caching的唯一方法是closures我的iPhone并再次打开它。 closures应用程序也没有帮助。

苹果的文档没有提到它,或者我错过了一些东西。 以防万一,应用程序是用monotouch创build的。

如果你想消除所有的caching响应,像这样的事情看起来像要走的路:

 [[NSURLCache sharedURLCache] removeAllCachedResponses]; 

有一个视图caching显示了最后一页使用的位图(就像我们在Safari中看到的那样),但是看起来并不像你所看到的(因为它需要重启设备)。

我从来没有注意到这种行为(从来没有find它;-)但下面的答案看起来很有希望。

FWIW这不是MonoTouch特有的。

我已经尝试了堆栈溢出的所有build议,并没有一个工作。 唯一的办法,我得到它的工作,并认为其可靠的解决scheme是创build一个临时目录(具有不同的目录名称 – 一个Guid最好的作品)的新HTML文件,并复制所有相关的图像,脚本,CSS ,每次到那个临时目录。

然后用NSUrlRequest对象打开它

 string tempdir = Path.Combine(UIController.Common.DataFolder,System.Guid.NewGuid().ToString ()); Directory.CreateDirectory (tempdir); //-- create your html on the tempdirectory here //-- copy all the images, and all the css, and js files UIWebView wv = new UIWebView(new RectangleF(30,30,480,680)); NSUrlRequest req = new NSUrlRequest(new NSUrl (Path.Combine (tempdir,"default.html"), false),NSUrlRequestCachePolicy.ReloadRevalidatingCacheData,10); wv.LoadFinished += delegate(object sender1, EventArgs e1) { //delete the tempdirectory Directory.Delete(tempdir); };