【发布时间】:2014-09-05 11:47:12
【问题描述】:
我们正在尝试将混合应用程序从 UIWebView (iOS DOM WebDatabase API(即“web sql 数据库”)存储内容时遇到 SecurityErrors。
如果 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 dom uiwebview web-sql wkwebview