[英]Cocoa: WKWebView local storage
I am trying to get local storage working with WKWebView
. 我正在尝试使本地存储与WKWebView
一起使用。
I have created a small demo project . 我创建了一个小型演示项目 。 It is a Mac app that shows a window with some buttons and a WKWebView
. 这是一个Mac应用程序,显示带有一些按钮和WKWebView
的窗口。
The three buttons show three variations of the same page: the Sticky Notes WebKit demo : 这三个按钮显示同一页面的三个变体: Sticky Notes WebKit演示 :
Remote loads the Sticky Notes WebKit demo page in the WKWebView
. 远程在WKWebView
加载Sticky Notes WebKit演示页面。
Local loads the same content from a copy in the app bundle. 本地从应用程序捆绑包中的副本加载相同的内容。
Safari loads the Sticky Notes WebKit demo in your browser. Safari会在浏览器中加载Sticky Notes WebKit演示 。
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. 我希望我在加载WKWebView
做错了WKWebView
,但是有可能不支持此操作。
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变量即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.