2012-02-16 151 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