localStorage在OSX应用程序(Xcode 4.3)中不持久 [英] localStorage not persisting in OSX app (Xcode 4.3)

查看:72
本文介绍了localStorage在OSX应用程序(Xcode 4.3)中不持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

From what I have seen, if you are building a OSX desktop HTML5 app and want localStorage to persist in your WebView wrapper, you need to do something like this:

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

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

但是这似乎不适用于Xcode 4.3.相反,我得到了

But this doesn't seem to work for me in Xcode 4.3. Instead I get

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

我对Objective C还是很陌生,可能正在做一些愚蠢的事情,例如不包含某些标头或其他内容.

I'm very new to Objective C, and are probably doing something silly like not including some header or something.

我包括了WebKit框架和这两个标头:

I've included the WebKit framework and both of these headers:

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

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

And what's weird is that I can access other methods of prefs, i.e. [prefs setDefaultFontSize:10] - but just not the two above that I listed.

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

Any ideas? Is this something that has been removed in Xcode 4.3?

推荐答案

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

OK, I have a solution. I looked at the source code to macgap and noticed how they were dealing with this issue.

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

It turns out the error message I was getting does make a little sense - I needed to declare an interface for WebPreferences first.

@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的新手.我真的不明白为什么需要接口才能调用这两个方法(即,当我可以在没有接口的情况下调用其他方法时).

Like I said, I'm new to Objective-C. I don't really get why the interface is needed in order to call those two methods (i.e. when I can call the other methods without the interface).

这篇关于localStorage在OSX应用程序(Xcode 4.3)中不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆