当 iPhone 5 应用程序处于后台时,Javascript 计时器不运行

标签 javascript html ios6

我正在运行一个 JavaScript 计时器,它在为 iPhone 5 构建的网络应用程序中播放蜂鸣声。当应用程序位于前台时,计时器工作正常。但是,当应用程序移至后台时,计时器不会运行,并且不会播放蜂鸣声。

下面是我的代码。

  setInterval( function(){ 
               beepAudio.get(0).play(); 
            }, timeInterval);

beepAudio是我嵌入html页面的音频标签的id。

我也尝试过 setTimeout,但没有帮助。 iOS版本为6.1.4。

当 iPhone 5 的应用程序处于后台时,有没有办法运行计时器?

感谢任何帮助。

最佳答案

来自App States and Multitasking后台执行和多任务部分(强调由我添加):

In iOS 4 and later, multitasking allows apps to continue running in the background even after the user switches to another app while still preserving battery life as much as possible. Most apps are moved to the suspended state shortly after entering the background. Only apps that provide important services to the user are allowed to continue running for any amount of time.

同一文档,关于暂停状态:

The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code.

所以你想要做的事情似乎是不可能的。

关于当 iPhone 5 应用程序处于后台时,Javascript 计时器不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18534415/

相关文章:

ios - iPad 的默认方向是什么?

objective-c - UICollectionView 重新排序动画

javascript - 从选择器中删除 keydown 事件不起作用?

javascript - 如何在开发html/js/css时进行MVC?

jquery - 如何计算顶部距离,用于在另一个 div 顶部定位标题?

html - 如何仅使用内联样式对齐表格行中图像链接旁边的文本链接?

ios - 我是否需要在 Thread 中运行 AudioServicesCreateSystemSoundID

javascript - 有没有办法更改 Node.js 网络(套接字)库中的 "on"监听器?

javascript - 将现有的点击功能重新附加到元素

PHP 函数到 Javascript : scan string and add words in array