Skip to content

Commit 8e3ef17

Browse files
committed
vk-1024-hybrid-router: restored NavigationService changes. Tests fixed.
1 parent c8937ff commit 8e3ef17

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

Sources/MapboxCoreNavigation/NavigationService.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import MapboxDirections
55
/**
66
A navigation service coordinates various nonvisual components that track the user as they navigate along a predetermined route. You use `MapboxNavigationService`, which conforms to this protocol, either as part of `NavigationViewController` or by itself as part of a custom user interface. A navigation service calls methods on its `delegate`, which conforms to the `NavigationServiceDelegate` protocol, whenever significant events or decision points occur along the route.
77

8-
A navigation service controls a `NavigationLocationManager` for determining the user’s location, a `Router` that tracks the user’s progress along the route, a `Directions` service for calculating new routes (only used when rerouting), and a `NavigationEventsManager` for sending telemetry events related to navigation or user feedback.
8+
A navigation service controls a `NavigationLocationManager` for determining the user’s location, a `Router` that tracks the user’s progress along the route, a `NavigationRouter` service for calculating new routes (only used when rerouting), and a `NavigationEventsManager` for sending telemetry events related to navigation or user feedback.
99

10-
`NavigationViewController` comes with a `MapboxNavigationService` by default. You may override it to customize the `Directions` service or simulation mode. After creating the navigation service, pass it into `NavigationOptions(styles:navigationService:voiceController:topBanner:bottomBanner:)`, then pass that object into `NavigationViewController(for:options:)`.
10+
`NavigationViewController` comes with a `MapboxNavigationService` by default. You may override it to customize the `NavigationRouter`'s source service or simulation mode. After creating the navigation service, pass it into `NavigationOptions(styles:navigationService:voiceController:topBanner:bottomBanner:)`, then pass that object into `NavigationViewController(for:options:)`.
1111

1212
If you use a navigation service by itself, outside of `NavigationViewController`, call `start()` when the user is ready to begin navigating along the route.
1313
*/
@@ -18,9 +18,14 @@ public protocol NavigationService: CLLocationManagerDelegate, RouterDataSource,
1818
var locationManager: NavigationLocationManager { get }
1919

2020
/**
21-
A reference to a MapboxDirections service. Used for rerouting.
21+
Routing source type used to create the route.
22+
*/
23+
var routingSource: NavigationRouter.RouterSource { get }
24+
25+
/**
26+
Credentials data, used to authorize server requests.
2227
*/
23-
var directions: Directions { get }
28+
var credentials: DirectionsCredentials { get }
2429

2530
/**
2631
The router object that tracks the user’s progress as they travel along a predetermined route.
@@ -270,7 +275,7 @@ public class MapboxNavigationService: NSObject, NavigationService {
270275
- parameter routeOptions: The route options used to get the route.
271276
*/
272277
convenience init(routeResponse: RouteResponse, routeIndex: Int, routeOptions options: RouteOptions) {
273-
self.init(routeResponse: routeResponse, routeIndex: routeIndex, routeOptions: options, directions: nil, locationSource: nil, eventsManagerType: nil)
278+
self.init(routeResponse: routeResponse, routeIndex: routeIndex, routeOptions: options, locationSource: nil, eventsManagerType: nil)
274279
}
275280

276281
/**
@@ -279,7 +284,8 @@ public class MapboxNavigationService: NSObject, NavigationService {
279284
- parameter routeResponse: `RouteResponse` object, containing selection of routes to follow.
280285
- parameter routeIndex: The index of the route within the original `RouteResponse` object.
281286
- parameter routeOptions: The route options used to get the route.
282-
- parameter directions: The Directions object that created `route`. If this argument is omitted, the shared value of `NavigationSettings.directions` will be used.
287+
- parameter routingSource: `NavigationRouter` source type, used to create route.
288+
- parameter credentials: Credentials to authorize additional data requests throughout the route. If this argument is omitted, the shared value of `NavigationSettings.directions` will be used.
283289
- parameter locationSource: An optional override for the default `NaviationLocationManager`.
284290
- parameter eventsManagerType: An optional events manager type to use while tracking the route.
285291
- parameter simulationMode: The simulation mode desired.
@@ -288,13 +294,15 @@ public class MapboxNavigationService: NSObject, NavigationService {
288294
required public init(routeResponse: RouteResponse,
289295
routeIndex: Int,
290296
routeOptions: RouteOptions,
291-
directions: Directions? = nil,
297+
routingSource: NavigationRouter.RouterSource = .hybrid,
298+
credentials: DirectionsCredentials = NavigationSettings.shared.directions.credentials,
292299
locationSource: NavigationLocationManager? = nil,
293300
eventsManagerType: NavigationEventsManager.Type? = nil,
294301
simulating simulationMode: SimulationMode? = nil,
295302
routerType: Router.Type? = nil) {
296303
nativeLocationSource = locationSource ?? NavigationLocationManager()
297-
self.directions = directions ?? NavigationSettings.shared.directions
304+
self.routingSource = routingSource
305+
self.credentials = credentials
298306
self.simulationMode = simulationMode ?? .inTunnels
299307
super.init()
300308
resumeNotifications()
@@ -307,12 +315,16 @@ public class MapboxNavigationService: NSObject, NavigationService {
307315
}
308316

309317
let routerType = routerType ?? DefaultRouter.self
310-
_router = routerType.init(alongRouteAtIndex: routeIndex, in: routeResponse, options: routeOptions, directions: self.directions, dataSource: self)
318+
_router = routerType.init(alongRouteAtIndex: routeIndex,
319+
in: routeResponse,
320+
options: routeOptions,
321+
routingSource: routingSource,
322+
dataSource: self)
311323
NavigationSettings.shared.distanceUnit = routeOptions.locale.usesMetric ? .kilometer : .mile
312324

313325
let eventType = eventsManagerType ?? NavigationEventsManager.self
314326
_eventsManager = eventType.init(activeNavigationDataSource: self,
315-
accessToken: self.directions.credentials.accessToken)
327+
accessToken: self.credentials.accessToken)
316328
locationManager.activityType = routeOptions.activityType
317329
bootstrapEvents()
318330

@@ -369,9 +381,14 @@ public class MapboxNavigationService: NSObject, NavigationService {
369381
private var simulatedLocationSource: SimulatedLocationManager?
370382

371383
/**
372-
A reference to a MapboxDirections service. Used for rerouting.
384+
Routing source type used to create the route.
385+
*/
386+
public var routingSource: NavigationRouter.RouterSource
387+
388+
/**
389+
Credentials data, used to authorize server requests.
373390
*/
374-
public var directions: Directions
391+
public var credentials: DirectionsCredentials
375392

376393

377394
// MARK: Managing Route-Related Data

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ extension RouteController: Router {
659659
changeRouteProgress(RouteProgress(route: route, options: routeOptions)) { [weak self] success in
660660
guard let self = self else { return }
661661
if success {
662-
self.announce(reroute: route, at: self.location, proactive: isProactive)
662+
self.announce(reroute: self.route, at: self.location, proactive: isProactive)
663663
self.indexedRouteResponse = indexedRouteResponse
664664
}
665665
completion?(success)

Sources/MapboxNavigation/NavigationViewController.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
8989
public var voiceController: RouteVoiceController!
9090

9191
func setupVoiceController() {
92-
let credentials = navigationService.directions.credentials
92+
let credentials = navigationService.credentials
9393
voiceController = navigationOptions?.voiceController
9494
?? RouteVoiceController(navigationService: navigationService,
9595
accessToken: credentials.accessToken,
@@ -177,13 +177,6 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
177177
var _routeIndex: Int?
178178
var _routeResponse: RouteResponse?
179179

180-
/**
181-
An instance of `Directions` need for rerouting. See [Mapbox Directions](https://docs.mapbox.com/ios/api/directions/) for further information.
182-
*/
183-
public var directions: Directions {
184-
return navigationService.directions
185-
}
186-
187180
/**
188181
The navigation service that coordinates the view controller’s nonvisual components, tracking the user’s location as they proceed along the route.
189182
*/

Tests/MapboxCoreNavigationTests/BillingHandlerTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,10 @@ final class BillingHandlerUnitTests: TestCase {
611611
.map { CLLocation(coordinate: $0) }
612612
.shiftedToPresent()
613613

614-
let directions = DirectionsSpy()
615-
616614
let navOptions = NavigationRouteOptions(coordinates: [origin, destination])
617615
let routeController = RouteController(alongRouteAtIndex: 0,
618616
in: routeResponse,
619617
options: navOptions,
620-
directions: directions,
621618
dataSource: self)
622619

623620
let routerDelegateSpy = RouterDelegateSpy()

Tests/MapboxNavigationTests/EndOfRouteFeedbackTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ final class EndOfRouteFeedbackTests: TestCase {
1616
let service = MapboxNavigationService(routeResponse: route.response,
1717
routeIndex: 0,
1818
routeOptions: options,
19-
directions: .mocked,
2019
locationSource: nil,
2120
eventsManagerType: nil,
2221
simulating: .never,

0 commit comments

Comments
 (0)