iPhone应用程序处于非活动状态时,NSTimer回调 [英] NSTimer callbacks while iPhone application is inactive

查看:138
本文介绍了iPhone应用程序处于非活动状态时,NSTimer回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎是这个论坛上其他几个人的精髓。我相信活动的iPhone应用程序可以继续运行,特别是在它进入非活动状态后(通过屏幕锁定中的空闲计时器或通过用户按下)继续接收计时器回叫硬件锁定按钮)。

This question seems to be the essence of several others on this forum. I believe that it is possible for the active iPhone application to continue running, and specifically, to continue receiving timer call-backs, after it has entered the inactive state (either through the idle timer kicking in the screen lock, or through the user pressing the hardware lock button).

文档明确指出,当应用程序处于非活动状态时,它正在执行,但不会调度传入的事件(我没有提供链接,因为我对NDA感到不满 - 我应该放松一下吗?这整个帖子是否违规?叹息)。

The documentation specifically says that while an application is inactive, it is executing, but not dispatching incoming events (I'm not giving a link because I'm jumpy about NDA - should I relax about that? Is this whole post a breach? sigh).

此外,用户Ambr Str直接回答两个问题声明可以继续接收定时器回叫,并且他提供了一段代码来实现它(我无法链接到此,因为我是新用户,抱歉 - 搜索问题:会发生什么iPhone进入待机模式时的iPhone应用程序?找到答案。

Also, two answers by user "Ambr Str" directly state that it is possible to continue receiving timer call-backs, and he supplies a snip of code to achieve it (I can't link to this because I'm a new user, sorry - search for the question: "What happens to an iPhone app when iPhone goes into stand-by mode?" to find his answer).

我试图按照他的建议创建我的回拨,但是一次我的应用程序变为非活动状态,回拨停止触发。

I've tried to create my call-backs as he suggests, but once my application becomes inactive, the call-backs cease firing.

我刚注意到,当iPhone插入时,如果应用程序变为非活动状态(由于空闲时间)或者我按下睡眠按钮),回拨确实继续发生 - 也许我应该让我的用户随身携带一个电池组; - )

I've just noticed that while the iPhone is plugged in, if the application becomes inactive (due to idle time out or me pressing the sleep button), call-backs do continue to occur - perhaps I should get my users to carry a battery pack with them ;-)

推荐答案

Apple的论坛上有一个很好的答案。搜索计时器和爱斯基摩人(提供答案的有帮助的人)。

There is a good answer to this question on Apple's forums. Search for "Timer" and "Eskimo" (the helpful chap who provides the answers).

简而言之,在应用程序变为非活动状态后不久,手机确实会转到睡觉。防止这种情况的唯一方法是播放一些音频(或者某些音频要在后台应用程序中播放)。当音频正在播放时,手机将无法休眠,并且您的应用程序将继续运行。

In brief, shortly after the application becomes inactive, the phone really does go to sleep. The only way to prevent this is to be playing some audio (or for some audio to be playing in a background application). While audio is playing the phone will not sleep, and your application continues to be run.

建议播放保持清醒的音频是一种黑客攻击,而且您不应该如果可能的话,这样做。我认为在我的应用程序中(其中散布着静音期的音频播放),该方法是有效的,如果不理想的话!

It is suggested that playing stay awake audio is a hack, and that you shouldn't do it if at all possible. I think in my application (which performs audio playback interspersed with silent periods), the approach is valid, if not ideal!

这篇关于iPhone应用程序处于非活动状态时,NSTimer回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆