Skip to content

Commit b06af4d

Browse files
committed
vk-1024-hybrid-router: CHANGELOG updated.
1 parent 27d8842 commit b06af4d

File tree

5 files changed

+54
-40
lines changed

5 files changed

+54
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
* Removed the `NavigationViewController.origin` property. ([#2808](https://github.com/mapbox/mapbox-navigation-ios/pull/2808))
183183
* Fixed a potential memory leak when using `MultiplexedSpeechSynthesizer`. ([#3005](https://github.com/mapbox/mapbox-navigation-ios/pull/3005))
184184
* Fixed a thread-safety issue in `UnimplementedLogging` protocol implementation. ([#3024](https://github.com/mapbox/mapbox-navigation-ios/pull/3024))
185+
* Replaced `Directions.calculateWithCache(options:completionHandler:)` and `Directions.calculateOffline(options:completionHandler)` functionality with `NavigationRouter`. It is now recommended to use `NavigationRouter` to request or refresh routes instead of `Directions` object. ([#3261](https://github.com/mapbox/mapbox-navigation-ios/pull/3261))
185186
* Fixed an issue where `UIApplication.shared.isIdleTimerDisabled` was not properly set in some cases. ([#3245](https://github.com/mapbox/mapbox-navigation-ios/pull/3245))
186187

187188
## v1.4.1

Sources/MapboxCoreNavigation/CacheHandlerFactory.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MapboxNavigationNative
44
protocol CacheHandlerData {
55
var tileStorePath: String { get }
66
var credentials: DirectionsCredentials { get }
7-
var tilesVersion: String? { get }
7+
var tilesVersion: String { get }
88
var historyDirectoryURL: URL? { get }
99
var targetVersion: String? { get }
1010
var configFactoryType: ConfigFactory.Type { get }
@@ -17,7 +17,7 @@ enum CacheHandlerFactory {
1717
private struct CacheKey: CacheHandlerData {
1818
let tileStorePath: String
1919
let credentials: DirectionsCredentials
20-
let tilesVersion: String?
20+
let tilesVersion: String
2121
let historyDirectoryURL: URL?
2222
let targetVersion: String?
2323
let configFactoryType: ConfigFactory.Type
@@ -31,12 +31,21 @@ enum CacheHandlerFactory {
3131
self.configFactoryType = data.configFactoryType
3232
}
3333

34+
private static func optionalsAreNotEqual<T: Comparable>(_ lhs: T?, _ rhs: T?) -> Bool{
35+
if let firstVal = lhs, let secondVal = rhs {
36+
return firstVal != secondVal
37+
}
38+
else {
39+
return lhs != nil || rhs != nil
40+
}
41+
}
42+
3443
static func != (lhs: CacheKey, rhs: CacheHandlerData) -> Bool {
3544
return lhs.tileStorePath != rhs.tileStorePath ||
3645
lhs.credentials != rhs.credentials ||
37-
lhs.tilesVersion != rhs.tilesVersion ||
38-
lhs.historyDirectoryURL != rhs.historyDirectoryURL ||
39-
lhs.targetVersion != rhs.targetVersion ||
46+
optionalsAreNotEqual(lhs.tilesVersion, rhs.tilesVersion) ||
47+
optionalsAreNotEqual(lhs.historyDirectoryURL?.absoluteString, rhs.historyDirectoryURL?.absoluteString) ||
48+
optionalsAreNotEqual(lhs.targetVersion, rhs.targetVersion) ||
4049
lhs.configFactoryType != rhs.configFactoryType
4150
}
4251
}

Sources/MapboxCoreNavigation/NativeHandlersFactory.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class NativeHandlersFactory {
1414

1515
let tileStorePath: String
1616
let credentials: DirectionsCredentials
17-
let tilesVersion: String?
17+
let tilesVersion: String
1818
let historyDirectoryURL: URL?
1919
let targetVersion: String?
2020
let configFactoryType: ConfigFactory.Type
2121

2222
init(tileStorePath: String,
2323
credentials: DirectionsCredentials,
24-
tilesVersion: String? = nil,
24+
tilesVersion: String = "",
2525
historyDirectoryURL: URL? = nil,
2626
targetVersion: String? = nil,
2727
configFactoryType: ConfigFactory.Type = ConfigFactory.self) {
@@ -71,7 +71,7 @@ class NativeHandlersFactory {
7171

7272
lazy var endpointConfig: TileEndpointConfiguration = {
7373
TileEndpointConfiguration(credentials: credentials,
74-
tilesVersion: tilesVersion ?? "",
74+
tilesVersion: tilesVersion,
7575
minimumDaysToPersistVersion: nil,
7676
targetVersion: targetVersion)
7777
}()

Sources/MapboxCoreNavigation/NavigationRouter.swift

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class NavigationRouter {
3333
Cancels the request if it is still active.
3434
*/
3535
public func cancel() {
36-
router.finish(request: id)
36+
router.router.cancelRequest(forToken: id)
3737
}
3838
}
3939

@@ -208,19 +208,15 @@ public class NavigationRouter {
208208

209209
// MARK: - Private methods
210210

211-
fileprivate func finish(request id: RequestId) {
212-
requestsLock.lock(); defer {
213-
requestsLock.unlock()
214-
}
215-
216-
router.cancelRequest(forToken: id)
217-
activeRequests[id] = nil
218-
}
219-
220211
fileprivate func complete(requestId: RequestId, with result: @escaping () -> Void) {
221-
DispatchQueue.main.async {
212+
DispatchQueue.main.async { [self] in
222213
result()
223-
self.finish(request: requestId)
214+
215+
requestsLock.lock(); defer {
216+
requestsLock.unlock()
217+
}
218+
219+
activeRequests[requestId] = nil
224220
}
225221
}
226222

@@ -286,7 +282,7 @@ public class NavigationRouter {
286282

287283
fileprivate func doRequest<ResponseType: Codable>(options: DirectionsOptions,
288284
completion: @escaping (Result<ResponseType, DirectionsError>) -> Void) -> RequestId {
289-
let directionsUri = settings.directions.url(forCalculating: options).absoluteString
285+
let directionsUri = settings.directions.url(forCalculating: options).removingSKU().absoluteString
290286
var requestId: RequestId!
291287
requestsLock.lock()
292288
requestId = router.getRouteForDirectionsUri(directionsUri) { [weak self] (result, _) in
@@ -307,6 +303,28 @@ public class NavigationRouter {
307303

308304
extension DirectionsProfileIdentifier {
309305
var nativeProfile: RoutingProfile {
310-
return RoutingProfile(profile: rawValue)
306+
var mode: RoutingMode
307+
switch self {
308+
case .automobile:
309+
mode = .driving
310+
case .automobileAvoidingTraffic:
311+
mode = .drivingTraffic
312+
case .cycling:
313+
mode = .cycling
314+
case .walking:
315+
mode = .walking
316+
default:
317+
mode = .driving
318+
}
319+
return RoutingProfile(mode: mode, account: "mapbox")
320+
}
321+
}
322+
323+
extension URL {
324+
func removingSKU() -> URL {
325+
var urlComponents = URLComponents(string: self.absoluteString)!
326+
let filteredItems = urlComponents.queryItems?.filter { $0.name != "sku" }
327+
urlComponents.queryItems = filteredItems
328+
return urlComponents.url!
311329
}
312330
}

Tests/MapboxCoreNavigationTests/RouteControllerTests.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,11 @@ class RouteControllerTests: TestCase {
121121
}
122122

123123
NavigationRouter.__testRoutesStub = { (options, completionHandler) in
124+
DispatchQueue.main.async {
125+
completionHandler(Directions.Session(options, .mocked),
126+
.success(routeResponse))
127+
}
124128
calculateRouteCalled.fulfill()
125-
let currentCoordinate = locationManager.location!.coordinate
126-
127-
let originWaypoint = Waypoint(coordinate: currentCoordinate)
128-
let destinationWaypoint = Waypoint(coordinate: destination)
129-
130-
let waypoints = [
131-
originWaypoint,
132-
destinationWaypoint
133-
]
134-
135-
completionHandler(Directions.Session(options, DirectionsCredentials()),
136-
.success(RouteResponse(httpResponse: nil,
137-
identifier: nil,
138-
routes: [Fixture.route(between: currentCoordinate,
139-
and: destination).route],
140-
waypoints: waypoints,
141-
options: .route(options),
142-
credentials: .mocked)))
143129
return 0
144130
}
145131

0 commit comments

Comments
 (0)