gpt4 book ai didi

ios - WKWebView 在将 html 和 javascript 与应用程序捆绑时给出 SecurityError

转载 作者:行者123 更新时间:2023-11-29 10:38:38 25 4
gpt4 key购买 nike

我们正在尝试将混合应用程序从 UIWebView (iOS < 8) 迁移到 WKWebView (iOS 8),但在尝试使用 DOM WebDatabase API 存储内容时出现安全错误(即“网络 sql 数据库”)。

如果 index.html 已从应用程序的捆绑文件中加载,则以下内容会引发错误

// throws SecurityError: DOM Exception 18
var db = openDatabase('mydb', '1.0', 'key value store', 1);

相同的代码在 UIWebView 上运行良好。出于某种原因,我可以回退到使用本地存储,但使用 WebSQL 数据库是行不通的。我只能推测这与同源策略或相关的东西有关。

有趣的是,从网络加载 index.html 工作正常:-/

关于我如何解决这个问题的任何线索?在修复它的 WKWebView 上设置任何选项?

这是我们加载网络相关内容的方式:

NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSURL *baseURL = [NSURL fileURLWithPath:htmlPath];
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];

WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
[config.userContentController addScriptMessageHandler:self.myCallbacks name:@"NativeApp"];

self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:config];

[self.webView loadRequest:request];

html 文件只是加载一个具有相对路径“myCode.js”的 javascript 文件。

最佳答案

iOS 8.0(我认为是 8.1 B1)中的 WKWebView 存在一个问题 ( OpenRadar ),导致它无法加载本地文件。它也可能影响本地存储。参见 this question了解更多详情。

关于ios - WKWebView 在将 html 和 javascript 与应用程序捆绑时给出 SecurityError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25685213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com