2012-02-16 80 views
0

当我在这里阅读时http://www.niallkennedy.com/blog/2008/02/iphone-cache-performance.html 重启后所有内容都消失了。可以使用本地存储来保存iOS上的缓存

因此,本地存储可以用来保持持久性,即使在重新启动后(在UIWebView中有一点Objective-C也许)?如果是的话有任何例子

+0

您可以使用NSHTTPCookieStorage。 Chech this [SO] [1] Q&A。 [1]:http://stackoverflow.com/questions/4597763/persisting-cookies-in-an-ios-application – user523234 2012-02-16 10:19:39

回答

1

是的,您可以写入应用程序文档目录。这将通过重新启动持续。

NSArray *paths = NSSearchPathForDirectoriesInDomains(
    NSDocumentDirectory, 
    NSUserDomainMask, 
    YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName]; 

[yourFile writeToFile:filePath atomically:YES]; 
+0

谢谢,但那么你的WebView加载? – user310291 2012-02-16 09:45:24

+0

正确,并且web视图中的html引用了缓存的文件。所以你应该将html文件写入缓存,以便它可以使用相对路径。 – Mundi 2012-02-17 09:48:10