我在程序工作中有一個webview的本地存儲,但它總是在下一次程序運行開始時被刪除。我檢查了這個文件,它在程序運行後仍然存在,但在下一個文件開始時,它將其清除。你如何設置本地存儲,使其在程序運行中持續存在
這裏是我的代碼:
- (void)awakeFromNib {
WebPreferences *prefs = [webView preferences];
[prefs _setLocalStorageDatabasePath:@"~/Library/Application Support/MyApp"];
[prefs setDatabasesEnabled:YES];
[prefs setLocalStorageEnabled:YES];
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/htdocs/index.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
[window setDelegate:self];
}
任何幫助,將不勝感激!由於
哦,這不適用於iOS ..我應該在下面閱讀您的免責聲明。以下兩個鏈接可能仍然對您有用:http://stackoverflow.com/questions/2640724 http://stackoverflow.com/questions/4625484/how-to-get-localstorage-to-work-in-a -webview-in-xcode – abelito 2011-12-31 10:55:48
我在發佈之前檢查了這兩個,但無法找到有用的信息。我知道localstorage應該是可能的,因爲它只是一個嵌入式webkit。 – NycCompSci 2012-01-04 03:23:08
這對我工作在10.7和Xcode 4.3.3:http://stackoverflow.com/questions/10609644/localstorage-not-persisting-in-osx-app-xcode-4-3 – endemic 2012-07-04 18:39:22