简体   繁体   English

可可:WKWebView本地存储

[英]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演示

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.

相关问题 持久存储Cocoa / MacOSX - Persistent Storage Cocoa/MacOSX 如何在目标C中删除可可应用程序(Mac)中的野生动物园历史记录,缓存,Cookie,热门站点,保存的状态和本地存储 - How to delete safari History, Cache, Cookies, Top sites, Saved state and local storage in cocoa app(Mac) in objective c 可可制作WKWebView命令+链接单击在新窗口中打开 - Cocoa make WKWebView command + link click open in new window WKWebView 可以加载本地 HTML5 进行写入吗? - Can WKWebView load local HTML5 for writing? MacOS中的WkWebView在本地或远程内容上保持空白 - WkWebView in MacOS remains blank on local or remote content OSX Sandbox WKWebView加载本地文件 - OSX Sandbox WKWebView Load Local File Inside 关于可可程序的程序布局和存储的建议,以进行分析 - Suggestions on program layout and storage of Cocoa program that analyzes 将文件拖动到Cocoa的WKWebView上的可拖动视图时,光标没有正确更改 - Cursor isn’t changed properly when drag a file to a draggable view on Cocoa's WKWebView 连接可移动存储时自动启动Cocoa应用程序 - auto launch Cocoa app when removable storage connected 访问活动页面的本地存储 - Access to local storage of active page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM