我正在使用Ionic构建我的混合应用程序。 在Android上我的应用运行得很好。现在我正在为iOS构建它,但是我的整个内容都被封装在内部Cordova设备未在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"/>
我真的不知道,我可以去解决这个bug。也许这与Content-Security-Policy有关,但我不知道如何解决这个问题。
在此先感谢您的帮助!
编辑: 我包裹着我的控制器(S)现在里面
$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'];
它仍然失败并引发了 “deviceready” 中的错误的console.log而我使用iOS模拟器进行测试。
谢谢@Pyro! 我不知道“document.addEventListener('deviceready',function()”已包含“$ ionicPlatform.ready” –
@StefanBlattmann有关其他参考:http://ionicframework.com/docs/api/utility/ ionic.Platform/ – HardikDG
如果这个答案可以帮助你,请选择正确的答案。谢谢 – HardikDG