swiftxcodeswiftuiapple-tv

Apple TV Not Stopping Screen Saver


My app needs to prevent the Apple screen saver from coming on automatically. I understand that to do this means inserting the following code into the launch with options function:

application.idleTimerDisabled = true

Additionally I understand that this may not work on a development build so I have tested it via a release build directly from Test Flight.

Net result is that it is not working. I have the Apple screen saver set to kick in at 2 minutes from the Apple settings screen. At exactly 2 minutes after inaction within my app, the screen saver fires off. In other words the above line of code is not working and I have been unable to find a different way or reason why.

Any idea why the above isn't working or if there is a different way to disable screen savers for Apple TV? This is running on tvOS 15.2.


Solution

  • Turns out the solution was to put it directly in the view (SwiftUI in this case) and not within

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
    

    When put into the .onAppear of the SwiftUI view as UIApplication.shared.isIdleTimerDisabled = true it worked.

    I'll leave this question up for others who will invariably find the same issue.