Skip to content

Instantly share code, notes, and snippets.

@hscheuerle
Created July 19, 2021 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hscheuerle/30bfa1e1bcf2e03dfa6cb2481ff8a1aa to your computer and use it in GitHub Desktop.
Save hscheuerle/30bfa1e1bcf2e03dfa6cb2481ff8a1aa to your computer and use it in GitHub Desktop.
import SwiftUI
struct ScreenLockModifier: ViewModifier {
func body(content: Content) -> some View {
content
.onAppear {
UIApplication.shared.isIdleTimerDisabled = true
}
.onDisappear {
UIApplication.shared.isIdleTimerDisabled = false
}
}
}
extension View {
func keepAwake() -> some View {
modifier(ScreenLockModifier())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment