diff --git a/apple/DemoApp/Demo/DemoNavigationView.swift b/apple/DemoApp/Demo/DemoNavigationView.swift index 10a3622b..ed56b33c 100644 --- a/apple/DemoApp/Demo/DemoNavigationView.swift +++ b/apple/DemoApp/Demo/DemoNavigationView.swift @@ -196,11 +196,14 @@ struct DemoNavigationView: View { route: route, config: config ) + + preventAutoLock() } func stopNavigation() { ferrostarCore.stopNavigation() camera = .center(initialLocation.coordinate, zoom: 14) + allowAutoLock() } var locationLabel: String { @@ -210,6 +213,14 @@ struct DemoNavigationView: View { return "±\(Int(userLocation.horizontalAccuracy))m accuracy" } + + private func preventAutoLock() { + UIApplication.shared.isIdleTimerDisabled = true + } + + private func allowAutoLock() { + UIApplication.shared.isIdleTimerDisabled = false + } } #Preview { diff --git a/guide/src/ios-getting-started.md b/guide/src/ios-getting-started.md index 5f322dec..488db7fe 100644 --- a/guide/src/ios-getting-started.md +++ b/guide/src/ios-getting-started.md @@ -150,6 +150,19 @@ DynamicallyOrientingNavigationView( useSnappedCamera: .constant(true)) ``` +## Preventing the screen from sleeping + +If you’re navigating, you probably don’t want the screen to go to sleep. +You can prevent this by setting the `isIdleTimerDisabled` property on the `UIApplication.shared` object. + +```swift +UIApplication.shared.isIdleTimerDisabled = true + +// Don't forget to re-enable it when you're done! +UIApplication.shared.isIdleTimerDisabled = false +``` + +Refer to the [Apple documentation](https://developer.apple.com/documentation/uikit/uiapplication/1623070-isidletimerdisabled) for more information. ## Demo app