【发布时间】:2016-03-25 16:17:30
【问题描述】:
我在使用 AngularJS 构建的 Cordova 应用程序中使用 SQlite。我引导应用程序 onDeviceReady() 然后检查是否存在数据库和特定表并根据结果执行某些操作。该应用程序在 Android 中按预期运行,但在 iOS 中它第一次运行,然后在模拟器或设备的白页上被阻止!谁能告诉我如何解决这个问题?
var db = window.sqlitePlugin.openDatabase(
// options
{
name: "users_info.db",
location: 2
},
// success callback
function (msg) {
// console.log("success: " + msg);
// console.log(msg);
},
// error callback
function (msg) {
// console.log("error: " + msg);
}
);
db.transaction(function (tx) {
tx.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name='user'", [], function (tx, result) {
if (result.rows.length == 0) {
console.log('theres no table with this name ');
$scope.$apply(function () {
$location.path('/login');
});
} else {
tx.executeSql(
"select * from user;",
[],
function (tx, res) {
var row = res.rows.item(0);
console.log(row.role);
if (row.role == 4) {
$scope.$apply(function () {
userService.roleid = '4';
userService.userid = row.userid;
$location.path('/student');
});
}
});
console.log('this table exists');
}
});
});
我也尝试了以下代码来打开数据库,但在 iOS 中,应用程序在第一次运行后再次冻结
var db = $cordovaSQLite.openDB({ name: "users_info.db", location: 1, iosDatabaseLocation: 'default' },
// success callback
function (msg) {
// console.log("success: " + msg);
console.log(msg);
console.log('success');
},
// error callback
function (msg) {
console.log("error: " + msg);
console.log('error');
}
);
【问题讨论】:
标签: ios angularjs sqlite cordova