【发布时间】:2015-06-07 12:50:18
【问题描述】:
我在 Ionic 应用程序中有以下代码行,当平台准备好时会触发(如下)。在 Chrome 上测试它时,它工作正常并且日志触发(“离子服务语法”)。在我的手机上,在 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)");
});
})
【问题讨论】:
标签: javascript sqlite cordova phonegap-build ionic