Skip to content

Commit 3b055bd

Browse files
authored
Update NavNative to v100 (#3888)
* vk-update-nn: bumped NN to v100. Updated routes setup code; CHANGELOG updated
1 parent ecefa81 commit 3b055bd

File tree

11 files changed

+45
-72
lines changed

11 files changed

+45
-72
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
* MapboxNavigation now requires [MapboxMaps v10.5.0](https://github.com/mapbox/mapbox-maps-ios/releases/tag/v10.5.0). ([#3869](https://github.com/mapbox/mapbox-navigation-ios/pull/3869))
88
* MapboxCoreNavigation now requires [MapboxDirections v2.5.0-beta.1](https://github.com/mapbox/mapbox-directions-swift/releases/tag/v2.5.0-beta.1). ([#3871](https://github.com/mapbox/mapbox-navigation-ios/pull/3871))
9-
* MapboxCoreNavigation now requires [MapboxNavigationNative v99._x_](https://github.com/mapbox/mapbox-navigation-native-ios/releases/tag/99.0.0). ([#3869](https://github.com/mapbox/mapbox-navigation-ios/pull/3869))
9+
* MapboxCoreNavigation now requires [MapboxNavigationNative v100._x_](https://github.com/mapbox/mapbox-navigation-native-ios/releases/tag/100.0.0). ([#3888](https://github.com/mapbox/mapbox-navigation-ios/pull/3888))
1010

1111
### User interface
1212

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 21.3.0
2-
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-navigation-native/MapboxNavigationNative.xcframework.json" ~> 99.0
2+
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-navigation-native/MapboxNavigationNative.xcframework.json" ~> 100.0
33
github "mapbox/mapbox-directions-swift" == 2.5.0-beta.1
44
github "mapbox/mapbox-events-ios" ~> 1.0.0

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "21.3.0"
2-
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-navigation-native/MapboxNavigationNative.xcframework.json" "99.0.0"
2+
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-navigation-native/MapboxNavigationNative.xcframework.json" "100.0.0"
33
github "Quick/Nimble" "v9.2.1"
44
github "Quick/Quick" "v3.1.2"
55
github "mapbox/mapbox-directions-swift" "v2.5.0-beta.1"

MapboxCoreNavigation.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Pod::Spec.new do |s|
4040
s.requires_arc = true
4141
s.module_name = "MapboxCoreNavigation"
4242

43-
s.dependency "MapboxNavigationNative", "~> 99.0"
43+
s.dependency "MapboxNavigationNative", "~> 100.0"
4444
s.dependency "MapboxDirections-pre", "2.5.0-beta.1"
4545
s.dependency "MapboxMobileEvents", "~> 1.0"
4646

MapboxNavigation-SPM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let package = Package(
2424
dependencies: [
2525
.package(name: "MapboxDirections", url: "https://github.com/mapbox/mapbox-directions-swift.git", .exact("2.5.0-beta.1")),
2626
.package(name: "MapboxMobileEvents", url: "https://github.com/mapbox/mapbox-events-ios.git", from: "1.0.0"),
27-
.package(name: "MapboxNavigationNative", url: "https://github.com/mapbox/mapbox-navigation-native-ios.git", from: "99.0.0"),
27+
.package(name: "MapboxNavigationNative", url: "https://github.com/mapbox/mapbox-navigation-native-ios.git", from: "100.0.0"),
2828
.package(name: "MapboxMaps", url: "https://github.com/mapbox/mapbox-maps-ios.git", from: "10.5.0"),
2929
.package(name: "Solar", url: "https://github.com/ceeK/Solar.git", from: "3.0.0"),
3030
.package(name: "MapboxSpeech", url: "https://github.com/mapbox/mapbox-speech-swift.git", from: "2.0.0"),

Sources/MapboxCoreNavigation/CoreNavigationNavigator.swift

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@ class Navigator {
3333
}
3434

3535
private lazy var routeCoordinator: RoutesCoordinator = {
36-
.init(mainRouteSetupHandler: { [weak self] route, legIndex, completion in
37-
self?.navigator.setPrimaryRouteForRoute(route, legIndex: legIndex) { [weak self] result in
36+
.init(routesSetupHandler: { [weak self] route, legIndex, alternativeRoutes, completion in
37+
var routesParams: SetRoutesParams? = nil
38+
if let route = route {
39+
routesParams = SetRoutesParams(primaryRoute: route,
40+
legIndex: legIndex,
41+
alternativeRoutes: alternativeRoutes)
42+
}
43+
44+
self?.navigator.setRoutesFor(routesParams) { [weak self] result in
3845
if result.isValue() {
39-
let routeInfo = result.value!
4046
os_log("Navigator has been updated",
4147
log: Navigator.log,
4248
type: .debug)
43-
completion(.success(routeInfo))
49+
completion(.success(route?.getRouteInfo()))
4450
}
4551
else if result.isError() {
4652
let reason = (result.error as String?) ?? ""
@@ -55,28 +61,6 @@ class Navigator {
5561
completion(.failure(NavigatorError.failedToUpdateRoutes(reason: "Unexpected internal response")))
5662
}
5763
}
58-
}, alternativeRoutesSetupHandler: { [weak self] routes, completion in
59-
self?.navigator.setAlternativeRoutesForRoutes(routes) { [weak self] result in
60-
if result.isValue() {
61-
let alternativeRoutes = result.value as? [RouteAlternative] ?? []
62-
os_log("Navigator Alternative Routes have been updated",
63-
log: Navigator.log,
64-
type: .debug)
65-
completion(.success(alternativeRoutes))
66-
}
67-
else if result.isError() {
68-
let reason = (result.error as String?) ?? ""
69-
os_log("Failed to update navigator Alternative Routes with reason: %{public}@",
70-
log: Navigator.log,
71-
type: .error,
72-
reason)
73-
completion(.failure(NavigatorError.failedToUpdateRoutes(reason: reason)))
74-
}
75-
else {
76-
assertionFailure("Invalid Expected value: \(result)")
77-
completion(.failure(NavigatorError.failedToUpdateRoutes(reason: "Unexpected internal response")))
78-
}
79-
}
8064
})
8165
}()
8266

@@ -237,15 +221,11 @@ class Navigator {
237221

238222
// MARK: - Navigator Updates
239223

240-
func setMainRoute(_ route: RouteInterface, uuid: UUID, legIndex: UInt32, completion: @escaping (Result<RouteInfo, Error>) -> Void) {
241-
routeCoordinator.beginActiveNavigation(with: route, uuid: uuid, legIndex: legIndex, completion: completion)
242-
}
243-
244-
func setAlternativeRoutes(_ routes: [RouteInterface], completion: @escaping (Result<[RouteAlternative], Error>) -> Void) {
245-
routeCoordinator.alternativeRoutesSetupHandler(routes, completion)
224+
func setRoutes(_ route: RouteInterface, uuid: UUID, legIndex: UInt32, alternativeRoutes: [RouteInterface], completion: @escaping (Result<RouteInfo?, Error>) -> Void) {
225+
routeCoordinator.beginActiveNavigation(with: route, uuid: uuid, legIndex: legIndex, alternativeRoutes: alternativeRoutes, completion: completion)
246226
}
247227

248-
func unsetRoutes(uuid: UUID, completion: @escaping (Result<RouteInfo, Error>) -> Void) {
228+
func unsetRoutes(uuid: UUID, completion: @escaping (Result<RouteInfo?, Error>) -> Void) {
249229
routeCoordinator.endActiveNavigation(with: uuid, completion: completion)
250230
}
251231

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ open class RouteController: NSObject {
263263
*/
264264
private func updateNavigator(with indexedRouteResponse: IndexedRouteResponse,
265265
fromLegIndex legIndex: Int,
266-
completion: ((Result<RouteInfo, Error>) -> Void)?) {
266+
completion: ((Result<RouteInfo?, Error>) -> Void)?) {
267267
guard case .route(let routeOptions) = indexedRouteResponse.routeResponse.options else {
268268
completion?(.failure(RouteControllerError.internalError))
269269
return
@@ -283,11 +283,10 @@ open class RouteController: NSObject {
283283
if parsedRoutes.isValue(),
284284
var routes = parsedRoutes.value as? [RouteInterface],
285285
routes.count > indexedRouteResponse.routeIndex {
286-
self.sharedNavigator.setMainRoute(routes.remove(at: indexedRouteResponse.routeIndex),
287-
uuid: sessionUUID,
288-
legIndex: UInt32(legIndex)) { [weak self] result in
289-
self?.sharedNavigator.setAlternativeRoutes(routes,
290-
completion: { _ in })
286+
self.sharedNavigator.setRoutes(routes.remove(at: indexedRouteResponse.routeIndex),
287+
uuid: sessionUUID,
288+
legIndex: UInt32(legIndex),
289+
alternativeRoutes: routes) { result in
291290
completion?(result)
292291
}
293292
} else if parsedRoutes.isError() {

Sources/MapboxCoreNavigation/RoutesCoordinator.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,21 @@ final class RoutesCoordinator {
1111
case activeNavigation(UUID)
1212
}
1313

14-
typealias MainRouteSetupHandler = (RouteInterface?, _ legIndex: UInt32, _ completion: @escaping (Result<RouteInfo, Error>) -> Void) -> Void
15-
typealias AlternativeRoutesSetupHandler = ([RouteInterface], _ completion: @escaping (Result<[RouteAlternative], Error>) -> Void) -> Void
14+
typealias RoutesSetupHandler = (_ mainRoute: RouteInterface?, _ legIndex: UInt32, _ alternativeRoutes: [RouteInterface], _ completion: @escaping (Result<RouteInfo?, Error>) -> Void) -> Void
1615

1716
private struct ActiveNavigationSession {
1817
let uuid: UUID
1918
}
2019

21-
private let mainRouteSetupHandler: MainRouteSetupHandler
22-
let alternativeRoutesSetupHandler: AlternativeRoutesSetupHandler
20+
private let routesSetupHandler: RoutesSetupHandler
2321
/// The lock that protects mutable state in `RoutesCoordinator`.
2422
private let lock: NSLock
2523
private var state: State
2624

2725
/// Create a new coordinator that will coordinate requests to set main and alternative routes.
28-
/// - Parameter mainRouteSetupHandler: The handler that passes `RouteInterface` object to underlying Navigator as main route.
29-
/// - Parameter alternativeRoutesSetupHandler: The handler that passes `RouteInterface` array to underlying Navigator as alternative routes.
30-
init(mainRouteSetupHandler: @escaping MainRouteSetupHandler,
31-
alternativeRoutesSetupHandler: @escaping AlternativeRoutesSetupHandler) {
32-
self.mainRouteSetupHandler = mainRouteSetupHandler
33-
self.alternativeRoutesSetupHandler = alternativeRoutesSetupHandler
26+
/// - Parameter routesSetupHandler: The handler that passes main and alternative route's`RouteInterface` objects to underlying Navigator.
27+
init(routesSetupHandler: @escaping RoutesSetupHandler) {
28+
self.routesSetupHandler = routesSetupHandler
3429
lock = .init()
3530
state = .passiveNavigation
3631
}
@@ -42,7 +37,8 @@ final class RoutesCoordinator {
4237
func beginActiveNavigation(with route: RouteInterface,
4338
uuid: UUID,
4439
legIndex: UInt32,
45-
completion: @escaping (Result<RouteInfo, Error>) -> Void) {
40+
alternativeRoutes: [RouteInterface],
41+
completion: @escaping (Result<RouteInfo?, Error>) -> Void) {
4642
lock.lock()
4743
if case .activeNavigation(let currentUUID) = state, currentUUID != uuid {
4844
os_log("[BUG] Two simultaneous active navigation sessions. This might happen if there are two NavigationViewController or RouteController instances exists at the same time. Profile the app and make sure that NavigationViewController is deallocated once not in use.", log: log, type: .fault)
@@ -51,12 +47,12 @@ final class RoutesCoordinator {
5147
state = .activeNavigation(uuid)
5248
lock.unlock()
5349

54-
mainRouteSetupHandler(route, legIndex, completion)
50+
routesSetupHandler(route, legIndex, alternativeRoutes, completion)
5551
}
5652

5753
/// - Parameters:
5854
/// - uuid: The UUID that was passed to `RoutesCoordinator.beginActiveNavigation(with:uuid:completion:)` method.
59-
func endActiveNavigation(with uuid: UUID, completion: @escaping (Result<RouteInfo, Error>) -> Void) {
55+
func endActiveNavigation(with uuid: UUID, completion: @escaping (Result<RouteInfo?, Error>) -> Void) {
6056
lock.lock()
6157
guard case .activeNavigation(let currentUUID) = state, currentUUID == uuid else {
6258
lock.unlock()
@@ -66,7 +62,7 @@ final class RoutesCoordinator {
6662
state = .passiveNavigation
6763
lock.unlock()
6864
// TODO: Is it safe to set the leg index to 0 when unsetting a route?
69-
mainRouteSetupHandler(nil, 0, completion)
65+
routesSetupHandler(nil, 0, [], completion)
7066
}
7167
}
7268

Tests/CocoaPodsTest/PodInstall/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PODS:
55
- MapboxCoreNavigation (2.5.0-beta.3):
66
- MapboxDirections-pre (= 2.5.0-beta.1)
77
- MapboxMobileEvents (~> 1.0)
8-
- MapboxNavigationNative (~> 99.0)
8+
- MapboxNavigationNative (~> 100.0)
99
- MapboxDirections-pre (2.5.0-beta.1):
1010
- Polyline (~> 5.0)
1111
- Turf (~> 2.0)
@@ -21,7 +21,7 @@ PODS:
2121
- MapboxMobileEvents (~> 1.0)
2222
- MapboxSpeech (~> 2.0)
2323
- Solar-dev (~> 3.0)
24-
- MapboxNavigationNative (99.0.0):
24+
- MapboxNavigationNative (100.0.0):
2525
- MapboxCommon (~> 21.3)
2626
- MapboxSpeech (2.0.0)
2727
- Polyline (5.0.2)
@@ -54,12 +54,12 @@ EXTERNAL SOURCES:
5454
SPEC CHECKSUMS:
5555
MapboxCommon: a336e40b53e3fda5c419fe093c9c40aff4f4dd2b
5656
MapboxCoreMaps: f0c995b043323571ec46d7d9e496390982f6509d
57-
MapboxCoreNavigation: 9ec6c23d03f9a3683104f18f9310aa910d0d6168
57+
MapboxCoreNavigation: 4cafbc4128960ff2b3d074132a1893276cb6a7f9
5858
MapboxDirections-pre: b267332f864b83bcdf8681d7e2a20ac045df1dad
5959
MapboxMaps: e85375aa3d6bea94bf9c0221aa59f35ee0b29f29
6060
MapboxMobileEvents: f7f3e8daeb4b83688ae62a4172dce79169a97233
6161
MapboxNavigation: 0e38c912839846bec00183f5ddb16ab59619b6c8
62-
MapboxNavigationNative: 4632bc7931369f87b495e81e3d6612b5c1808648
62+
MapboxNavigationNative: b934e3b705c46590f918c7b8991700d4523bf220
6363
MapboxSpeech: e4ed02984444b6373374c72c369edaf045cc490c
6464
Polyline: fce41d72e1146c41c6d081f7656827226f643dff
6565
Solar-dev: 4612dc9878b9fed2667d23b327f1d4e54e16e8d0

0 commit comments

Comments
 (0)