diff --git a/Navigation-Examples.xcodeproj/project.pbxproj b/Navigation-Examples.xcodeproj/project.pbxproj index 4fdfb578..df6f9327 100644 --- a/Navigation-Examples.xcodeproj/project.pbxproj +++ b/Navigation-Examples.xcodeproj/project.pbxproj @@ -13,9 +13,11 @@ 2B521D4E24090A3A00984CF8 /* CustomBarsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B521D4D24090A3A00984CF8 /* CustomBarsViewController.swift */; }; 2B521D502409240E00984CF8 /* CustomBottomBannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B521D4F2409240E00984CF8 /* CustomBottomBannerView.swift */; }; 2B521D522409242A00984CF8 /* CustomBottomBannerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2B521D512409242A00984CF8 /* CustomBottomBannerView.xib */; }; + 8A0B182326553482005107DE /* CustomSegue.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8A0B182226553482005107DE /* CustomSegue.storyboard */; }; 8A2DFA57261650A60034A87E /* CustomCameraStateTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A2DFA55261650A60034A87E /* CustomCameraStateTransition.swift */; }; 8A2DFA58261650A60034A87E /* CustomViewportDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A2DFA56261650A60034A87E /* CustomViewportDataSource.swift */; }; 8A2DFA6C261651600034A87E /* Custom-Navigation-Camera.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A2DFA6B261651600034A87E /* Custom-Navigation-Camera.swift */; }; + 8A31388726402DF400763714 /* Navigation-From-Segue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A31388626402DF400763714 /* Navigation-From-Segue.swift */; }; 8A33629624E4844E0086C647 /* Building-Extrusion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A33629524E4844E0086C647 /* Building-Extrusion.swift */; }; 8A96379C2492B366008DEF2A /* Route-Deserialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A96379A2492B366008DEF2A /* Route-Deserialization.swift */; }; 8A96379D2492B366008DEF2A /* route.json in Resources */ = {isa = PBXBuildFile; fileRef = 8A96379B2492B366008DEF2A /* route.json */; }; @@ -57,9 +59,11 @@ 2B521D4D24090A3A00984CF8 /* CustomBarsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomBarsViewController.swift; sourceTree = ""; }; 2B521D4F2409240E00984CF8 /* CustomBottomBannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomBottomBannerView.swift; sourceTree = ""; }; 2B521D512409242A00984CF8 /* CustomBottomBannerView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CustomBottomBannerView.xib; sourceTree = ""; }; + 8A0B182226553482005107DE /* CustomSegue.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CustomSegue.storyboard; sourceTree = ""; }; 8A2DFA55261650A60034A87E /* CustomCameraStateTransition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomCameraStateTransition.swift; sourceTree = ""; }; 8A2DFA56261650A60034A87E /* CustomViewportDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomViewportDataSource.swift; sourceTree = ""; }; 8A2DFA6B261651600034A87E /* Custom-Navigation-Camera.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Custom-Navigation-Camera.swift"; sourceTree = ""; }; + 8A31388626402DF400763714 /* Navigation-From-Segue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Navigation-From-Segue.swift"; sourceTree = ""; }; 8A33629524E4844E0086C647 /* Building-Extrusion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Building-Extrusion.swift"; sourceTree = ""; }; 8A96379A2492B366008DEF2A /* Route-Deserialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Route-Deserialization.swift"; sourceTree = ""; }; 8A96379B2492B366008DEF2A /* route.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = route.json; sourceTree = ""; }; @@ -173,6 +177,15 @@ path = TestData; sourceTree = ""; }; + 8AFBF217265E851700468551 /* CustomSegue */ = { + isa = PBXGroup; + children = ( + 8A31388626402DF400763714 /* Navigation-From-Segue.swift */, + 8A0B182226553482005107DE /* CustomSegue.storyboard */, + ); + path = CustomSegue; + sourceTree = ""; + }; 961FC4E622E0260A00C72877 /* DocsCode */ = { isa = PBXGroup; children = ( @@ -249,11 +262,12 @@ 8A96379A2492B366008DEF2A /* Route-Deserialization.swift */, 8AC9129C2494106100B6941E /* Route-Initialization.swift */, 8A33629524E4844E0086C647 /* Building-Extrusion.swift */, - 8A2DFA52261650600034A87E /* NavigationCamera */, B480E423261E4C3500C16FA0 /* Predictive-Caching.swift */, B480E427261E4C4600C16FA0 /* Route-Alerts.swift */, 11DC36F126161DAF0042CD4A /* Location-Snapping.swift */, 11B6E81626176F3600872E4D /* Upcoming-Intersection.swift */, + 8AFBF217265E851700468551 /* CustomSegue */, + 8A2DFA52261650600034A87E /* NavigationCamera */, 8AC9129E2494118400B6941E /* TestData */, 2B521D5324094F2500984CF8 /* CustomBars */, ); @@ -372,6 +386,7 @@ 8A96379D2492B366008DEF2A /* route.json in Resources */, 2B521D522409242A00984CF8 /* CustomBottomBannerView.xib in Resources */, C58FB8611FE899B800C4B491 /* Assets.xcassets in Resources */, + 8A0B182326553482005107DE /* CustomSegue.storyboard in Resources */, 9639244A22E02A520010FE73 /* Main.storyboard in Resources */, 9639244B22E02A820010FE73 /* EmbeddedExamples.storyboard in Resources */, ); @@ -557,6 +572,7 @@ B480E424261E4C3500C16FA0 /* Predictive-Caching.swift in Sources */, C5C0D63820589422003A3B1D /* Custom-Server.swift in Sources */, C3893F1C25F96BDC0058A987 /* Custom-Waypoints.swift in Sources */, + 8A31388726402DF400763714 /* Navigation-From-Segue.swift in Sources */, 2B521D4E24090A3A00984CF8 /* CustomBarsViewController.swift in Sources */, 8A96379C2492B366008DEF2A /* Route-Deserialization.swift in Sources */, 2B521D502409240E00984CF8 /* CustomBottomBannerView.swift in Sources */, diff --git a/Navigation-Examples/Base.lproj/Main.storyboard b/Navigation-Examples/Base.lproj/Main.storyboard index f8e86dbb..ed44f59e 100644 --- a/Navigation-Examples/Base.lproj/Main.storyboard +++ b/Navigation-Examples/Base.lproj/Main.storyboard @@ -1,12 +1,9 @@ - - - - + + - - + @@ -20,7 +17,7 @@ - + @@ -58,25 +55,25 @@ - + - + - + - + @@ -87,6 +84,7 @@ + @@ -95,13 +93,13 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Navigation-Examples/Examples/CustomSegue/Navigation-From-Segue.swift b/Navigation-Examples/Examples/CustomSegue/Navigation-From-Segue.swift new file mode 100644 index 00000000..109b0813 --- /dev/null +++ b/Navigation-Examples/Examples/CustomSegue/Navigation-From-Segue.swift @@ -0,0 +1,75 @@ +import UIKit +import MapboxNavigation +import MapboxCoreNavigation +import MapboxDirections + +class SegueViewController: UIViewController { + + var route: Route! + + var navigationRouteOptions: NavigationRouteOptions! + + var navigationOptions: NavigationOptions! + + @IBOutlet weak var presentNavigationButton: UIButton! + + override func viewDidLoad() { + super.viewDidLoad() + + setupPresentNavigationButton() + + let origin = CLLocationCoordinate2DMake(37.77440680146262, -122.43539772352648) + let destination = CLLocationCoordinate2DMake(37.76556957793795, -122.42409811526268) + navigationRouteOptions = NavigationRouteOptions(coordinates: [origin, destination]) + + Directions.shared.calculate(navigationRouteOptions) { [weak self] (session, result) in + switch result { + case .failure(let error): + NSLog("Error occured: \(error.localizedDescription).") + case .success(let response): + guard let route = response.routes?.first, let self = self else { return } + + self.route = route + + let navigationService = MapboxNavigationService(route: route, + routeIndex: 0, + routeOptions: self.navigationRouteOptions, + simulating: simulationIsEnabled ? .always : .onPoorGPS) + self.navigationOptions = NavigationOptions(navigationService: navigationService) + } + } + } + + func setupPresentNavigationButton() { + presentNavigationButton.titleLabel?.textAlignment = .center + presentNavigationButton.titleLabel?.numberOfLines = 2 + presentNavigationButton.titleLabel?.lineBreakMode = .byTruncatingTail + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // To create an instance of `NavigationViewController` + // from `UIStoryboardSegue` `route`, `routeIndex` and `routeOptions` + // properties of `NavigationViewController` must be pre-defined. + switch segue.identifier ?? "" { + case "NavigationSegue": + if let navigationViewController = segue.destination as? NavigationViewController { + navigationViewController.route = route + navigationViewController.routeIndex = 0 + navigationViewController.routeOptions = navigationRouteOptions + // `navigationOptions` property is optional. + navigationViewController.navigationOptions = navigationOptions + navigationViewController.delegate = self + navigationViewController.modalPresentationStyle = .fullScreen + } + default: + break + } + } +} + +extension SegueViewController: NavigationViewControllerDelegate { + + func navigationViewControllerDidDismiss(_ navigationViewController: NavigationViewController, byCanceling canceled: Bool) { + dismiss(animated: true) + } +} diff --git a/Podfile.lock b/Podfile.lock index e57b858c..13a5a9be 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -56,10 +56,10 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: MapboxCoreNavigation: - :commit: 2fc35deb98c9bf9e200dd829a7e66dd8ec4ae6f2 + :commit: aef35fc88c2bd972cef6365ac8fbd911fd28ba7e :git: https://github.com/mapbox/mapbox-navigation-ios.git MapboxNavigation: - :commit: 2fc35deb98c9bf9e200dd829a7e66dd8ec4ae6f2 + :commit: aef35fc88c2bd972cef6365ac8fbd911fd28ba7e :git: https://github.com/mapbox/mapbox-navigation-ios.git SPEC CHECKSUMS: