gpt4 book ai didi

javascript - SQLite 插件在 Mac 和 Windows 上工作,但在手机上的 Safari 中不工作

转载 作者:行者123 更新时间:2023-11-30 16:57:43 26 4
gpt4 key购买 nike

我在 Ionic 应用程序中有以下代码行,它会在平台准备就绪时触发(如下)。在 Chrome 上测试它时,它工作正常并且会触发日志(“Ionic Serve Syntax”)。在我的手机上,在 Safari 中,没有任何反应,基本上没有触发 - 看起来数据库甚至没有打开。

以下代码均无效(设备准备就绪后):

db = window.openDatabase("starter.db", "1.0", "My app", -1) // Nope

db = $cordovaSQLite.openDB("starter.db"); // Nope

如果数据库没有正确安装,那么它应该也不能在 Chrome 中运行,对吧?还是我没有正确安装 SQlite?

我也在云平台(cloud9)上测试它,这可能与它有关吗?

.run(function($ionicPlatform, $cordovaSQLite, DebugConsole) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}

if(window.cordova) {
// App syntax
console.log("App syntax")
db = $cordovaSQLite.openDB("starter.db");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
} else {
// Ionic serve syntax
console.log("Ionic serve syntax")
db = window.openDatabase("starter.db", "1.0", "My app", -1);
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
}

//$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS team (id integer primary key, name text)");

});
})

最佳答案

请替换以下行

          db = window.openDatabase("starter.db", "1.0", "My app", -1);

通过以下行

        db = window.openDatabase("starter.db", '1', 'My app', 1024 * 1024 * 100); // browser 

请尝试使用适用于 Chrome 和 Safari 的代码

    .run(function($ionicPlatform, $cordovaSQLite, DebugConsole) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}

if(window.cordova) {
// App syntax
console.log("App syntax")
db = $cordovaSQLite.openDB("starter.db");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
} else {
// Ionic serve syntax
console.log("Ionic serve syntax")
db = window.openDatabase("starter.db", '1', 'My app', 1024 * 1024 * 100); // browser
// db = window.openDatabase("starter.db", "1.0", "My app", -1);
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
}

//$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS team (id integer primary key, name text)");

});
})

关于javascript - SQLite 插件在 Mac 和 Windows 上工作,但在手机上的 Safari 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29415100/

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