localStorage not persisting in OSX app (Xcode 4.3)

后端 未结 3 1878
庸人自扰
庸人自扰 2021-01-05 04:05

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:



        
3条回答
  •  星月不相逢
    2021-01-05 04:32

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

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

    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).

提交回复
热议问题