菜鸟教程小白 发表于 2022-12-12 16:32:14

ios - 在 Titanium 中,暂停事件和 ios 中的 registerBackgroundService 有什么区别?


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

<pre><code>service = Ti.App.iOS.registerBackgroundService({
    url:&#34;bg.js&#34;
});
</code></pre>

<p>bg.js:</p>

<pre><code>var sec = 0;
setInterval(function(){console.log(&#39;counting&#39; + sec); sec = sec + 1}, 1000);
</code></pre>

<p>版本 2:
app.js</p>

<pre><code>Titanium.App.addEventListener(&#39;pause&#39;, function(){
    var sec = 0;
    setInterval(function(){console.log(&#39;counting&#39; + sec); sec = sec + 1}, 1000);
});
</code></pre>

<p>版本 1 和版本 2 执行完全相同的操作(当应用程序置于后台时)。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>版本 1 和版本 2 做的事情不同。 <a href="http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.App.iOS.BackgroundService" rel="noreferrer noopener nofollow">Background service</a>是当应用程序被放置在后台时运行的服务,当应用程序从后台返回时它会自动停止。它可以调用<a href="http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.App.iOS.LocalNotification" rel="noreferrer noopener nofollow">Titanium.App.iOS.LocalNotification</a> .</p>
<p> <a href="http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.App-event-pause" rel="noreferrer noopener nofollow">pause</a>是当应用程序在多任务系统上从事件状态转换到非事件状态时触发的事件。当用户离开应用程序或某些类型的临时中断(例如通知或来电)时触发此事件。</p>
<p>来自文档,</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>两者不同,做不同的工作</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 Titanium 中,暂停事件和 ios 中的 registerBackgroundService 有什么区别?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/20078443/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/20078443/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 Titanium 中,暂停事件和 ios 中的 registerBackgroundService 有什么区别?