我试图在我的离子应用程序中使用背景模式插件,但我遇到了一个问题。
我想做与backgroundmode.onactivate
的github项目自述文件中显示的内容相同的内容。
如果它仅在第二次进入后台时才起作用,那将完全正常。
如果有人对这个问题有任何了解,我很高兴听到这个问题:)
我的代码示例:
$ionicPlatform.ready(function() {
document.addEventListener('deviceready', function () {
// Android customization
cordova.plugins.backgroundMode.setDefaults({ text:'Doing heavy tasks.'});
// Enable background mode
cordova.plugins.backgroundMode.enable();
if(cordova.plugins.backgroundMode.isEnabled()){
console.log('Hi, I am enabled. Signed : backgroundMode.');
}
// Called when background mode has been activated
cordova.plugins.backgroundMode.onactivate = function () {
setTimeout(function () {
// Modify the currently displayed notification
cordova.plugins.backgroundMode.configure({
text:'Running in background for more than 5s now.'
});
console.log('Running in background for more than 5s now.');
}, 5000);
}
}, false);
注意:我的应用程序启动时,我确实得到了行Hi, I am enabled. Signed : backgroundMode.
。
答案 0 :(得分:0)
我改变了解决问题的方法。我虽然无法理解这个错误:(
i