简体   繁体   中英

Cocoa: WKWebView local storage

I am trying to get local storage working with WKWebView .

I have created a small demo project . It is a Mac app that shows a window with some buttons and a WKWebView .

The three buttons show three variations of the same page: the Sticky Notes WebKit demo :

The first two do not work; the latter does.

What should happen is it should appear with one default sticky note, and an enabled New Note button will add new sticky notes.

In the Remote and Local variations, no note appears, and the New Note button is disabled, indicating that it couldn't access the local storage.

I'm hoping that I'm just doing something wrong in loading the WKWebView , but it's possible that this just isn't supported.

Here's my code for the Remote variation:

WKWebViewConfiguration *config = [WKWebViewConfiguration new];

config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];

self.webView = [[WKWebView alloc] initWithFrame:self.container.frame configuration:config];
self.webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;

[self.container addSubview:self.webView];

NSURL *url = [NSURL URLWithString:@"https://webkit.org/demos/sticky-notes/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

[self.webView loadRequest:request];

Any assistance much appreciated!

更新:事实证明,虽然我正在使用的本地存储机制在Safari中WKWebView ,但在WKWebView中却WKWebView ,但它比预期的要容易:仅使用localStorage JavaScript变量即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM