Iphone app is delayed for 10 -15 minutes when iphone is in sleep mode

前端 未结 4 756
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 13:43

I have created an app that uses NSTimer, which gets triggered each second.

My problem is that if the Iphone is in sleep mode i get a delay for 10 to 15 minutes befo

4条回答
  •  执念已碎
    2021-01-07 14:20

    When the iPhone goes to sleep, so does your app and the runloop that runs the NSTimer.

    You seem to think that an NSTimer is some sort of hardware based timer. It is not. It operates completely within the software of the app that launches it. I don't know what is waking your app up but it is definitely not the NSTimer.

    In short, what you want to do is impossible. You can't sleep the phone and then have an app still active and running. The mute sound technique is just a kludge to keep the phone awake and the app running.

    If you need the phone to stay awake, you need to set the application's idleTimerDisabled to YES. This will prevent the phone from sleeping and the app can remain active. But once you let the phone sleep, it cannot be awaken from app code. Only the hardware can do that in response to an alarm or an incoming message.

提交回复
热议问题