localStorage不能持久存在于OSX应用程序中(Xcode 4.3)

asg*_*eo1 8 macos webkit objective-c local-storage xcode4.3

根据我的看法,如果您正在构建OSX桌面HTML5应用程序并希望localStorage在WebView包装器中持久存在,则需要执行以下操作:

WebPreferences* prefs = [webView preferences];
[prefs _setLocalStorageDatabasePath:@"~/Library/Application Support/MyApp"];
[prefs setLocalStorageEnabled:YES];
Run Code Online (Sandbox Code Playgroud)

摘自:如何在基于WebKit的应用程序中启用本地存储?

但在Xcode 4.3中,这似乎对我没有用.相反,我得到了

"No visible @interface for 'WebPreferences' declares the selector '_setLocalStorageDatabasePath:'
"No visible @interface for 'WebPreferences' declares the selector 'setLocalStorageEnabled:'
Run Code Online (Sandbox Code Playgroud)

我对Objective C很新,并且可能正在做一些愚蠢的事情,比如不包括一些标题或其他东西.

我已经包含了WebKit框架和这两个标头:

#import <WebKit/WebKit.h>
#import <WebKit/WebPreferences.h>
Run Code Online (Sandbox Code Playgroud)

奇怪的是,我可以访问其他prefs方法,即[prefs setDefaultFontSize:10]- 但不是我列出的上述两种方法.

有任何想法吗?这是Xcode 4.3中删除的内容吗?

asg*_*eo1 5

好的,我有一个解决方案.我查看了macgap的源代码,并注意到他们是如何处理这个问题的.

事实证明我得到的错误消息确实有点意义 - 我需要首先为WebPreferences声明一个接口.

@interface WebPreferences (WebPreferencesPrivate)
- (void)_setLocalStorageDatabasePath:(NSString *)path;
- (void) setLocalStorageEnabled: (BOOL) localStorageEnabled;
@end

...

WebPreferences* prefs = [WebPreferences standardPreferences];
[prefs _setLocalStorageDatabasePath:"~/Library/Application Support/MyApp"];
[prefs setLocalStorageEnabled:YES];
[webView setPreferences:prefs];
Run Code Online (Sandbox Code Playgroud)

就像我说的,我是Objective-C的新手.我真的不明白为什么需要接口来调用这两个方法(即当我可以在没有接口的情况下调用其他方法时).