简体   繁体   中英

iOS App prevents device from sleep mode

I've a really strange behavior of my iOS app. It prevents the device from going to standby. I've already searched if there is anywhere the idleTimeDisabled flag set, but this isn't the case. The idle timer inside the settings app is set to 2 minutes and works within other apps. The device isn't jailbroken and the even restarting the device didn't help. The app was written by somebody else and I'm new to it. So in the moment I don't have any idea what to look for. Has anybody of you an idea, why this could be the case or how I could figure out what's the reason for this behavior?

Thank you very much!

Put this line in your ViewController that require not being in sleep mode

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most applications should let the system turn off the screen when the idle timer elapses. This includes audio applications. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction.

If your app is using AVPlayer or some other similar AVFoundation functionality, this can be the cause.

If AVPlayer is playing a video, a device will not go to sleep while a video is playing.

If the video is playing in a loop, the device will never go to sleep.

Edit: With iOS 12 this is now possible by setting

player.preventsDisplaySleepDuringVideoPlayback = false

Make sure you are not "testing" with your Xcode. Because it will always remained as turn on status as long as you plugin your iPhone with a cable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM