objective-c - localStorage 不存在于 OSX 应用程序中 (Xcode 4.3)

标签 objective-c macos webkit local-storage xcode4.3

据我所知,如果您正在构建 OSX 桌面 HTML5 应用程序并希望 localStorage 保留在您的 WebView 包装器中,您需要执行如下操作:

WebPreferences* prefs = [webView preferences];
[prefs _setLocalStorageDatabasePath:@"~/Library/Application Support/MyApp"];
[prefs setLocalStorageEnabled:YES];

取自:How do I enable Local Storage in my WebKit-based application?

但这在 Xcode 4.3 中似乎对我不起作用。相反,我得到了

"No visible @interface for 'WebPreferences' declares the selector '_setLocalStorageDatabasePath:'
"No visible @interface for 'WebPreferences' declares the selector 'setLocalStorageEnabled:'

我是 Objective C 的新手,可能正在做一些愚蠢的事情,比如不包含一些 header 或其他东西。

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

#import <WebKit/WebKit.h>
#import <WebKit/WebPreferences.h>

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

有什么想法吗?这是 Xcode 4.3 中删除的东西吗?

最佳答案

好的,我有办法。我查看了 macgap 的源代码并注意到他们是如何处理这个问题的。

事实证明,我收到的错误消息确实有点道理 - 我需要先为 WebPreferences 声明一个接口(interface)。

@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];

正如我所说,我是 Objective-C 的新手。我真的不明白为什么需要接口(interface)才能调用这两种方法(即什么时候我可以在没有接口(interface)的情况下调用其他方法)。

关于objective-c - localStorage 不存在于 OSX 应用程序中 (Xcode 4.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10609644/

相关文章:

ios - AVAssetImageGenerator 性能问题

python - 找不到 appcfg.py 或 dev_appserver.py?

macos - 如何将 Objective C 静态库导入 Swift Framework?

javascript - 水平滚动时如何防止浏览器在历史记录中后退/前进?

objective-c - NSPredicate 表达式过滤一对多关系的计数

iphone - 如何避免从照片库中选择或从 ios 中的相机捕获的图像的背景?

ios - Objective C数组计数字符串问题

在 OS X 下编译 libmms

javascript - 由于 webkit 自动填充,无法在输入中键入

javascript - WebKit及其旧式前缀