Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent auto lock screen while navigating on iOS #163

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apple/DemoApp/Demo/DemoNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions guide/src/ios-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading