Sleep Screen

Hi everyone.

I try to do an app without UIKit and only with SwiftUI features.

I specify to use the @main Xcode beta 12 way and not the "old" appDelegate way.

How to do ( to disable sleep screen in app ) :
Code Block
UIApplication.shared.isIdleTimerDisabled = true

on this :
Code Block
@main
struct MyNewApp: App {
var body: some Scene {
Text("Hello world")
}
}

Thank you.
You can add this to the App’s body content
Code Block Swift
.onAppear {
UIApplication.shared.isIdleTimerDisabled = true
}

or add this if you changed your mind
Code Block Swift
struct MyNewApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
Text("Hello world")
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
application.isIdleTimerDisabled = true
return true
}
}

Sleep Screen
 
 
Q