Created
July 19, 2021 15:13
-
-
Save hscheuerle/30bfa1e1bcf2e03dfa6cb2481ff8a1aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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