> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/ios/navigation/v2/llms.txt)

# User notifications

If your application is in the background or the screen is locked during turn-by-turn navigation, `NavigationViewController` can automatically display local user notifications to inform the user of upcoming maneuvers. These notifications contain the same information as the instruction banners that would be visible on the screen if your application were in the foreground. Tapping on a notification brings `NavigationViewController` back to the foreground.

![Local device notification on iOS.](https://docs.mapbox.com/ios/assets/ideal-img/navigation-guide-device-notification.75a20c0.480.png)

## Asking for permission to display notifications

The user needs to allow your application to display local user notifications. At some point before presenting `NavigationViewController`, such as when the application launches, [ask the user for permission](https://developer.apple.com/documentation/usernotifications/asking_permission_to_use_notifications) by calling the `UNUserNotificationCenter.requestAuthorization(options:completionHandler:)` method. This method is asynchronous, so if you also need to request Location Services authorization at the same time, call the `CLLocationManager.requestWhenInUseAuthorization()` method inside its completion handler:

```swift
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) { _, _ in
    DispatchQueue.main.async {
        CLLocationManager().requestWhenInUseAuthorization()
    }
}
```

As long as your application is allowed to display user notifications, `NavigationViewController` displays them at the same time as spoken instructions. If you want the user to receive notifications from another part of your application but not from `NavigationViewController`, set the [`NavigationViewController.sendsNotifications`](https://docs.mapbox.com/ios/navigation/api/2.21.0/Classes/NavigationViewController.html#/s:16MapboxNavigation0B14ViewControllerC18sendsNotificationsSbvp) property to `false`.

## Displaying notifications manually

Your application can also manually display user notifications about the navigation session. For example, you can use a notification to inform the user about application-specific aspects of the trip or to have more fine-grained control over their timing. Manually displayed notifications can also be part of a custom turn-by-turn navigation interface that does not use `NavigationViewController`.

To manually display a user notification, implement the [`NavigationServiceDelegate.navigationService(_:didPassSpokenInstructionPoint:routeProgress:)`](https://docs.mapbox.com/ios/navigation/api/2.21.0/Protocols/NavigationServiceDelegate.html#/s:16MapboxNavigation0B15ServiceDelegateP010navigationC0_29didPassSpokenInstructionPoint13routeProgressyAA0bC0_p_0A10Directions0hI0CAA05RouteL0CtF) method. Inside your implementation, populate a `UNMutableNotificationContent` using the current visual instruction, which you can get using the [`RouteProgress.currentLegProgress`](https://docs.mapbox.com/ios/navigation/api/2.21.0/Classes/RouteProgress.html#/s:16MapboxNavigation13RouteProgressC010currentLegD0AA0cfD0Cvp), [`RouteLegProgress.currentStep`](https://docs.mapbox.com/ios/navigation/api/2.21.0/Classes/RouteLegProgress.html#/s:16MapboxNavigation16RouteLegProgressC11currentStep0A10Directions0cG0Cvp), and [`RouteStep.instructionsDisplayedAlongStep`](https://docs.mapbox.com/ios/directions/api/2.14.4/Classes/RouteStep.html#/s:16MapboxDirections9RouteStepC026instructionsDisplayedAlongD0SayAA23VisualInstructionBannerCGSgvp) properties. [Schedule this notification locally](https://developer.apple.com/documentation/usernotifications/scheduling_a_notification_locally_from_your_app).

## Further resources

-   [`Notification.Name` API reference](https://docs.mapbox.com/ios/navigation/api/2.21.0/Extensions/Notification/Name.html)
-   [`NotificationUserInfoKey` API reference](https://docs.mapbox.com/ios/navigation/api/2.21.0/Classes/RouteController/NotificationUserInfoKey.html)