OGeek|极客世界-中国程序员成长平台

标题: ios - 在 Titanium 中,暂停事件和 ios 中的 registerBackgroundService 有什么区别? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:32
标题: ios - 在 Titanium 中,暂停事件和 ios 中的 registerBackgroundService 有什么区别?

简而言之,当您可以通过将函数附加到“暂停”事件来做类似的事情时,拥有 Ti.App.iOS.registerBackgroundService 有什么意义? Titanium 中的两种方法之间有什么区别吗? 例如 版本 1: app.js:

service = Ti.App.iOS.registerBackgroundService({
    url:"bg.js"
});

bg.js:

var sec = 0;
setInterval(function(){console.log('counting' + sec); sec = sec + 1}, 1000);

版本 2: app.js

Titanium.App.addEventListener('pause', function(){
    var sec = 0;
    setInterval(function(){console.log('counting' + sec); sec = sec + 1}, 1000);
});

版本 1 和版本 2 执行完全相同的操作(当应用程序置于后台时)。



Best Answer-推荐答案


版本 1 和版本 2 做的事情不同。 Background service是当应用程序被放置在后台时运行的服务,当应用程序从后台返回时它会自动停止。它可以调用Titanium.App.iOS.LocalNotification .

pause是当应用程序在多任务系统上从事件状态转换到非事件状态时触发的事件。当用户离开应用程序或某些类型的临时中断(例如通知或来电)时触发此事件。

来自文档,

Note that calls to functions that modify the UI during this event may be partially executed, up to the UI call before the suspension. See paused event. If this happens, the remainder of the code will be executed after the application is resumed, but before the resume event is triggered.

两者不同,做不同的工作

关于ios - 在 Titanium 中,暂停事件和 ios 中的 registerBackgroundService 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20078443/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4