|

楼主 |
发表于 2016-5-23 22:15:23
|
显示全部楼层
在main.w/js里添加了事件
var timer="";
Model.prototype.modelLoad = function(event){
//延迟创建不影响显示
setTimeout(justep.Util.bindModelFn(this,function(){this.createAgent();},this),0);
if(this.getContext().isDebug()){
$(".debug-mode",this.getRootNode()).removeClass('hide');
$(".x-portal-reload",this.getRootNode()).removeClass('hide');
}
//增加自定义的图标数字显示
document.addEventListener('deviceready', function() {
cordova.plugins.backgroundMode.onactivate = function() {
var counter = 0;
timer = setInterval(function() {
counter++;
console.log('Running since ' + counter + ' sec');
if (device.platform != 'Android') {
cordova.plugins.notification.badge.set(counter);
}
// if (counter % 15 === 0) {
// cordova.plugins.backgroundMode.configure({
// text : 'Running since ' + counter + ' sec'
// });
// }
}, 2000);
};
cordova.plugins.backgroundMode.ondeactivate = function() {
clearInterval(timer);
cordova.plugins.notification.badge.clear();
};
}, false);
//设置
cordova.plugins.backgroundMode.enable();
//增加自定义数字显示结束
};
Model.prototype.modelUnLoad = function(event){
clearInterval(timer);
cordova.plugins.notification.badge.clear();
};
登录进去后,回到苹果桌面,图标上数字累加显示。返回app,注销(没有从内存后台清除app),再返回苹果桌面,数字又开始从1累加显示。
是哪里定时清的不对? |
|