'SwiftUI UIApplication.shared.isIdleTimerDisabled = true just on one View
How can i turn Sleep off when just one View is Appeared ?
UIApplication.shared.isIdleTimerDisabled = true stop the screen from going to sleep on every View.
how just in ContentView ?
struct ContentView: View {
UIApplication.shared.isIdleTimerDisabled = true
}
Solution 1:[1]
Use onAppear and onDisappear:
var body: some View {
Text("Hi there")
.onAppear { UIApplication.shared.isIdleTimerDisabled = true }
.onDisappear { UIApplication.shared.isIdleTimerDisabled = false }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
