Skip to main content

Storyboards

To set up Mapbox Navigation in a storyboard:

  • Open the object library and drag in a new ViewController.
  • Set Class to NavigationViewController.
  • Set Module to MapboxNavigationUIKit.

When you create a NavigationViewController instance from a storyboard, you need to pass a navigationRoutes and a navigationOptions to a newly created instance via prepareViewLoading(navigationRoutes:navigationOptions:) method.

To do that, override your UIViewController's prepare(for:sender:):

var mapboxNavigationProvider = MapboxNavigationProvider(coreConfig: .init())
var routingProvider = mapboxNavigationProvider.mapboxNavigation.routingProvider()
self.navigationRoutes = try? await routingProvider.calculateRoutes(options: options).value
// Make sure to deinitialize the previous MapboxNavigationProvider instance before starting the segue.

override func prepare(for segue: UIStoryboardSegue, sender _: Any?) {
switch segue.identifier {
case "MyNavigationSegue":
if let controller = segue.destination as? NavigationViewController,
let navigationProvider = controller.mapboxNavigation as? MapboxNavigationProvider
{
let navigationOptions = NavigationOptions(
mapboxNavigation: controller.mapboxNavigation,
voiceController: navigationProvider.routeVoiceController,
eventsManager: controller.mapboxNavigation.eventsManager()
)
_ = controller.prepareViewLoading(navigationRoutes: navigationRoutes, navigationOptions: navigationOptions)
}
default:
break
}
}
Was this page helpful?