There's an AVPlayer
instance that prevents iOS device display from sleeping.
If I comment out player.play()
method (where player
is AVPlayer
) then the device does go to sleep correctly after idle timeout, so I've pinpointed the issue to AVPlayer
instance being played.
I've set preventsDisplaySleepDuringVideoPlayback
to false
(tried both before and after play
call) yet it doesn't seem to work.
I'm also not setting isIdleTimerDisabled
to false
either (though if it was the case then it shouldn't have gone to sleep anyway in the case where I don't call play
either).
I also stop debugging from Xcode and run the app manually, since Xcode debugger prevents sleep anyway.
What might be the culprit? (I'm on latest iOS 17.6.1, it's a React Native app though I've pinpointed the issue so RN side shouldn't matter).
After trial and error I've realized where preventsDisplaySleepDuringVideoPlayback
is set to false
is particularly important.
Setting it right before or after did not work though setting it right after creating AVPlayer
instance worked.