How to stop the screen from going to sleep

How to stop the screen from going to sleep in the iPad app on macOS? This solution does not help "UIApplication.shared.isIdleTimerDisabled = true"

If you write code like that in function and then call the function?

    private func disableIdleTimer() {
#if os(iOS)
           UIApplication.shared.isIdleTimerDisabled = true
#elseif os(macOS)
        NSApplication.shared.isIdleTimerDisabled = true
#endif
    }
    
    private func enableIdleTimer() {
#if os(iOS)
          UIApplication.shared.isIdleTimerDisabled = false
#elseif os(macOS)
        NSApplication.shared.isIdleTimerDisabled = false
#endif
    }
}
How to stop the screen from going to sleep
 
 
Q