我正在使用 Ionic 构建我的混合应用程序。 在 Android 上,我的应用程序运行良好。现在我正在为 iOS 构建它,但我的全部内容都包含在里面
document.addEventListener('deviceready', function () {
console.log('dashboard -> device ready');
// copy database to the device
DbAccess.copyDb();
}, false);
在 iOS 中不会触发。
然后我用 iOS 模拟器试了一下
$ ionic emulate ios --livereload
并检查了 console.log。
结果:
1 709252 log deviceready has not fired after 5 seconds.
2 709253 log Channel not fired: onCordovaInfoReady
我遵循了我在这里和通过谷歌找到的建议,但不幸的是没有任何成功(删除 ios 并重新添加等)
我的版本:
Cordova: 6.1.1
Ionic: 1.7.14
我在 index.html 中的安全设置:
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
在我的 config.xml 中:
<access origin="geo:*" launch-external="yes"/>
<access origin="tel:*" launch-external="yes"/>
<access origin="mailto:*" launch-external="yes"/>
我真的不知道我可以在哪里继续解决这个错误。也许是 Content-Security-Policy 的问题,但我不知道如何解决。
预先感谢您的帮助!
编辑: 我现在将我的 Controller 包裹在里面
$ionicPlatform.ready(function() {...});
例如:
var dashboardCtrl = function ($scope, $ionicPlatform, $cordovaDevice, DbAccess) {
console.log('dashboardCtrl');
$ionicPlatform.ready(function () {
console.log('dashboard -> platform ready');
document.addEventListener('deviceready', function () {
console.log('dashboard -> device ready');
// copy database to the device
DbAccess.copyDb();
}, false);
});
};
dashboardCtrl.$inject = ['$scope', '$ionicPlatform', '$cordovaDevice', 'DbAccess'];
当我使用 iOS 模拟器对其进行测试时,它仍然失败并在 console.log 中抛出“deviceready”错误。
最佳答案
如果您使用 Ionic 为什么要手动使用 document.addEventListener('deviceready', function ()
$ionicPlatform.ready
给您的结果与cordova的'deviceready',无需再次调用deviceready。
另一件事,你不应该把就绪函数放在 Controller 的自定义函数中。 不应该这样使用
$scope.logInSubmit = function (details) {}
或
var submit = function () {}
如果您检查Ionic 示例,您将更好地了解这两个项目(例如:ionic start myApp 选项卡)
在 Ionic 中你的代码可以是这样的
$ionicPlatform.ready(function() {
console.log('dashboard -> device ready');
//you can load your plugins or custom objects inside this device ready
}
关于ios - Cordova deviceready 不在 iOS 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36694353/