0

如果您构建一个简单的 Titanium 移动应用程序,其中包含一个 WebView,其中包含打开本地数据库的 javascript,第一次将其安装到 iOS 5.1 设备时,它将正确打开数据库。但是,如果您随后在设备上升级应用程序(它仍然可以是完全相同的版本/构建),则在打开本地数据库时会出错:

SECURITY_ERR:DOM 异常 18

重现步骤:

  1. 将下面的 app.js 和 database.html 文件添加到 Resources 的根目录。
  2. 将应用程序安装到 iOS 5.1 设备(在 Ti Studio 中运行 > iOS 设备)。
  3. 打开应用程序,它会说“db opens”。
  4. 在 iOS 5.1 设备上升级应用程序(Ti Studio 中的运行 > iOS 设备)。
  5. 打开应用程序,它会说“db opening failed: Error: SECURITY_ERR: DOM Exception 18”。

这是重现的代码:

应用程序.js:

var win = Ti.UI.createWindow({});
var webView = Ti.UI.createWebView({
    top : 0, right : 0, bottom : 0, left : 0, url: 'database.html'
});
win.add(webView);
win.open();

数据库.html:

<!DOCTYPE HTML>
<html>
    <head>
        <title>db test</title>
        <script>
            window.onload = function () {
                var dbConn;
                try {
                    dbConn = openDatabase('test', '0.1', 'test database', 5 * 1024 * 1024);
                    alert('db opened');
                } catch (e) {
                    alert('db opening failed: ' + e.toString());
                }
            };
        </script> 
    </head>
    <body>
        db test
    </body>
</html>

这个问题似乎与 Apache Cordova 拥有并修复的问题相同。

https://issues.apache.org/jira/browse/CB-347

有没有其他人遇到过这个问题?任何解决方法的想法?

4

1 回答 1

0

我们最终为 iOS 创建了一个自定义 webview 模块来自己解决这个问题,因为谁知道 Titanium 需要多长时间才能做到这一点:

Webview 模块源码

于 2013-01-28T15:30:51.020 回答