Skip to content

Commit 1431939

Browse files
authored
Merge pull request #2876 from mapbox/shan/core-tests-integration-2874
Allow the Navigator set access token other than in Info.plist
2 parents 1526797 + 7069c40 commit 1431939

18 files changed

+69
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* Removed `NavigationViewController.origin` property, which was not used. ([#2808](https://github.com/mapbox/mapbox-navigation-ios/pull/2808))
5353
* A new predictive cache proactively fetches tiles which may become necessary if the device loses its Internet connection at some point during passive or active turn-by-turn navigation. Pass a `PredictiveCacheOptions` instance into the `NavigationOptions(styles:navigationService:voiceController:topBanner:bottomBanner:predictiveCacheOptions:)` initializer as you configure a `NavigationViewController`, or manually call `NavigationMapView.enablePredictiveCaching(options:)`. ([#2830](https://github.com/mapbox/mapbox-navigation-ios/pull/2830))
5454
* Added the `Directions.calculateOffline(options:completionHandler:)` and `Directions.calculateWithCache(options:completionHandler:)` methods, which incorporate routing tiles from the predictive cache when possible to avoid relying on a network connection to calculate the route. `RouteController` now also uses the predictive cache when rerouting. ([#2848](https://github.com/mapbox/mapbox-navigation-ios/pull/2848))
55+
* Added the `Navigator.credentials` to accept `DirectionsCredentials` from `PassiveLocationDataSource`, `RouteController` and `PredictiveCacheManager`. Added the `PredictiveCacheOptions.credentials` to allow developers dynamically switching between access tokens. ([#2876](https://github.com/mapbox/mapbox-navigation-ios/pull/2876))
5556

5657
## v1.3.0
5758

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,6 +3307,7 @@
33073307
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
33083308
SKIP_INSTALL = YES;
33093309
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
3310+
SYSTEM_FRAMEWORK_SEARCH_PATHS = "";
33103311
TARGETED_DEVICE_FAMILY = "1,2";
33113312
};
33123313
name = Debug;
@@ -3343,6 +3344,7 @@
33433344
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.TestHelper;
33443345
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
33453346
SKIP_INSTALL = YES;
3347+
SYSTEM_FRAMEWORK_SEARCH_PATHS = "";
33463348
TARGETED_DEVICE_FAMILY = "1,2";
33473349
};
33483350
name = Release;

Sources/MapboxCoreNavigation/BundleAdditions.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ extension Bundle {
2323
}
2424
}
2525

26-
var locationAlwaysUsageDescription: String? {
27-
get {
28-
return object(forInfoDictionaryKey: "NSLocationAlwaysUsageDescription") as? String
29-
}
30-
}
31-
3226
/**
3327
The Mapbox Core Navigation framework bundle.
3428
*/

Sources/MapboxCoreNavigation/CoreNavigationNavigator.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class Navigator {
4545
return RoadObjectsStore(try! navigator.roadObjectStore())
4646
}()
4747

48+
/**
49+
The Authorization & Authentication credentials that are used for this service. If not specified - will be automatically intialized from the token and host from your app's `info.plist`.
50+
51+
- precondition: `credentials` should be set before getting the shared navigator for the first time.
52+
*/
53+
static var credentials: DirectionsCredentials? = nil
54+
4855
/**
4956
Provides a new or an existing `MapboxCoreNavigation.Navigator` instance. Upon first initialization will trigger creation of `MapboxNavigationNative.Navigator` and `HistoryRecorderHandle` instances,
5057
satisfying provided configuration (`tilesVersion` and `tilesURL`).
@@ -68,7 +75,7 @@ class Navigator {
6875
let settingsProfile = SettingsProfile(application: ProfileApplication.kMobile,
6976
platform: ProfilePlatform.KIOS)
7077

71-
let endpointConfig = TileEndpointConfiguration(credentials: Directions.shared.credentials,
78+
let endpointConfig = TileEndpointConfiguration(credentials:Navigator.credentials ?? Directions.shared.credentials,
7279
tilesVersion: Self.tilesVersion,
7380
minimumDaysToPersistVersion: nil)
7481

Sources/MapboxCoreNavigation/LegacyRouteController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,10 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa
405405
guard let _ = Bundle.main.bundleIdentifier else {
406406
return
407407
}
408-
if Bundle.main.locationAlwaysUsageDescription == nil && Bundle.main.locationWhenInUseUsageDescription == nil && Bundle.main.locationAlwaysAndWhenInUseUsageDescription == nil {
409-
preconditionFailure("This application’s Info.plist file must include a NSLocationWhenInUseUsageDescription. See https://developer.apple.com/documentation/corelocation for more information.")
408+
if Bundle.main.locationWhenInUseUsageDescription == nil && Bundle.main.locationAlwaysAndWhenInUseUsageDescription == nil {
409+
if UserDefaults.standard.object(forKey: "NSLocationWhenInUseUsageDescription") == nil && UserDefaults.standard.object(forKey: "NSLocationAlwaysAndWhenInUseUsageDescription") == nil {
410+
preconditionFailure("This application’s Info.plist file must include a NSLocationWhenInUseUsageDescription. See https://developer.apple.com/documentation/corelocation for more information.")
411+
}
410412
}
411413
}
412414

Sources/MapboxCoreNavigation/NavigationService.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ private func checkForLocationUsageDescription() {
575575
guard let _ = Bundle.main.bundleIdentifier else {
576576
return
577577
}
578-
if Bundle.main.locationAlwaysUsageDescription == nil && Bundle.main.locationWhenInUseUsageDescription == nil && Bundle.main.locationAlwaysAndWhenInUseUsageDescription == nil {
579-
preconditionFailure("This application’s Info.plist file must include a NSLocationWhenInUseUsageDescription. See https://developer.apple.com/documentation/corelocation for more information.")
578+
if Bundle.main.locationWhenInUseUsageDescription == nil && Bundle.main.locationAlwaysAndWhenInUseUsageDescription == nil {
579+
if UserDefaults.standard.object(forKey: "NSLocationWhenInUseUsageDescription") == nil && UserDefaults.standard.object(forKey: "NSLocationAlwaysAndWhenInUseUsageDescription") == nil {
580+
preconditionFailure("This application’s Info.plist file must include a NSLocationWhenInUseUsageDescription. See https://developer.apple.com/documentation/corelocation for more information.")
581+
}
580582
}
581583
}

Sources/MapboxCoreNavigation/PassiveLocationDataSource.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ open class PassiveLocationDataSource: NSObject {
2020
*/
2121
public required init(directions: Directions = Directions.shared, systemLocationManager: NavigationLocationManager? = nil) {
2222
self.directions = directions
23+
Navigator.credentials = directions.credentials
2324

2425
self.systemLocationManager = systemLocationManager ?? NavigationLocationManager()
2526

Sources/MapboxCoreNavigation/PredictiveCacheManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class PredictiveCacheManager {
1818
- parameter mapOptions: Information about `MapView` tiles such as the location and tilesets to cache. If this argument is set to `nil`, predictive caching is disabled for map tiles.
1919
*/
2020
public init(predictiveCacheOptions: PredictiveCacheOptions, mapOptions: MapOptions?) {
21+
Navigator.credentials = predictiveCacheOptions.credentials
2122
self.controllers.append(initNavigatorController(options: predictiveCacheOptions))
2223
if let mapOptions = mapOptions {
2324
self.controllers.append(contentsOf: initMapControllers(options: predictiveCacheOptions, mapOptions: mapOptions))

Sources/MapboxCoreNavigation/PredictiveCacheOptions.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MapboxNavigationNative
2-
2+
import MapboxDirections
33
/**
44
Specifies the content that a predictive cache fetches and how it fetches the content.
55

@@ -35,6 +35,11 @@ public struct PredictiveCacheOptions {
3535
*/
3636
public var maximumConcurrentRequests: UInt32 = 2
3737

38+
/**
39+
The Authorization & Authentication credentials that are used for this service. If not specified - will be automatically intialized from the token and host from your app's `info.plist`.
40+
*/
41+
public var credentials: DirectionsCredentials = .init()
42+
3843
public init() {
3944
// No-op
4045
}

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ open class RouteController: NSObject {
152152

153153
required public init(along route: Route, routeIndex: Int, options: RouteOptions, directions: Directions = Directions.shared, dataSource source: RouterDataSource) {
154154
self.directions = directions
155+
Navigator.credentials = directions.credentials
155156
self._routeProgress = RouteProgress(route: route, routeIndex: routeIndex, options: options)
156157
self.dataSource = source
157158
self.refreshesRoute = options.profileIdentifier == .automobileAvoidingTraffic && options.refreshingEnabled

0 commit comments

Comments
 (0)