Skip to content

Commit 986003c

Browse files
authored
Make NavigationService optional to be able to skip implementation of delegate method on client side. (#3208)
Make `NavigationService` optional to be able to skip implementation of delegate method on client side as `CarPlayManager` provides default `MapboxNavigationService` implementation anyway.
1 parent b4f00ef commit 986003c

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
* Added the `CarPlayMapViewControllerDelegate` public protocol, which provides methods for reacting to events during free-drive navigation or route previewing. ([#3190](https://github.com/mapbox/mapbox-navigation-ios/pull/3190))
9999
* Added the `CarPlayMapViewControllerDelegate.carPlayMapViewController(_:didAdd:pointAnnotationManager:)`, `CarPlayNavigationViewControllerDelegate.carPlayNavigationViewController(_:didAdd:pointAnnotationManager:)` and `CarPlayManager.carPlayManager(_:didAdd:to:pointAnnotationManager:)` delegate methods, which will be called whenever the `PointAnnotation` representing the final destination is added to `CarPlayMapViewController`, `CarPlayNavigationViewController` and `CarPlayManager`, respectively. ([#3190](https://github.com/mapbox/mapbox-navigation-ios/pull/3190))
100100
* Added the ability to show speed limit indicator on CarPlay during free-drive. ([#3197](https://github.com/mapbox/mapbox-navigation-ios/pull/3197))
101+
* `CarPlayManagerDelegate.carPlayManager(_:navigationServiceAlong:routeIndex:routeOptions:desiredSimulationMode:)` now requires optional `NavigationService`. In case if `NavigationService` was not provided `MapboxNavigationService` will be used by default. ([#3208](https://github.com/mapbox/mapbox-navigation-ios/pull/3208))
102+
* `CarPlayManagerDelegate.carplayManagerShouldDisableIdleTimer(_:)` was renamed to `CarPlayManagerDelegate.carPlayManagerShouldDisableIdleTimer(_:)`. ([#3208](https://github.com/mapbox/mapbox-navigation-ios/pull/3208))
101103

102104
### Other changes
103105

Example/AppDelegate+CarPlay.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension AppDelegate: CarPlayManagerDelegate {
7373
navigationServiceAlong route: Route,
7474
routeIndex: Int,
7575
routeOptions: RouteOptions,
76-
desiredSimulationMode: SimulationMode) -> NavigationService {
76+
desiredSimulationMode: SimulationMode) -> NavigationService? {
7777
if let navigationViewController = self.window?.rootViewController?.presentedViewController as? NavigationViewController,
7878
let navigationService = navigationViewController.navigationService {
7979
// Do not set simulation mode if we already have an active navigation session.

Sources/MapboxNavigation/CarPlayManager.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ extension CarPlayManager: CPApplicationDelegate {
286286
interfaceController.delegate = self
287287
self.interfaceController = interfaceController
288288

289-
if let shouldDisableIdleTimer = delegate?.carplayManagerShouldDisableIdleTimer(self) {
289+
if let shouldDisableIdleTimer = delegate?.carPlayManagerShouldDisableIdleTimer(self) {
290290
UIApplication.shared.isIdleTimerDisabled = shouldDisableIdleTimer
291291
} else {
292292
UIApplication.shared.isIdleTimerDisabled = true
@@ -321,7 +321,7 @@ extension CarPlayManager: CPApplicationDelegate {
321321

322322
eventsManager.sendCarPlayDisconnectEvent()
323323

324-
if let shouldDisableIdleTimer = delegate?.carplayManagerShouldDisableIdleTimer(self) {
324+
if let shouldDisableIdleTimer = delegate?.carPlayManagerShouldDisableIdleTimer(self) {
325325
UIApplication.shared.isIdleTimerDisabled = !shouldDisableIdleTimer
326326
} else {
327327
UIApplication.shared.isIdleTimerDisabled = false
@@ -564,7 +564,8 @@ extension CarPlayManager: CPMapTemplateDelegate {
564564
let desiredSimulationMode: SimulationMode = simulatesLocations ? .always : .onPoorGPS
565565

566566
let navigationService = self.navigationService ??
567-
delegate?.carPlayManager(self, navigationServiceAlong: route,
567+
delegate?.carPlayManager(self,
568+
navigationServiceAlong: route,
568569
routeIndex: routeIndex,
569570
routeOptions: options,
570571
desiredSimulationMode: desiredSimulationMode) ??
@@ -576,7 +577,7 @@ extension CarPlayManager: CPMapTemplateDelegate {
576577
// Store newly created `MapboxNavigationService`.
577578
self.navigationService = navigationService
578579

579-
if simulatesLocations == true {
580+
if simulatesLocations {
580581
navigationService.simulationSpeedMultiplier = simulatedSpeedMultiplier
581582
}
582583
popToRootTemplate(interfaceController: interfaceController, animated: false)
@@ -867,7 +868,7 @@ extension CarPlayManager {
867868
interfaceController.delegate = self
868869
self.interfaceController = interfaceController
869870

870-
if let shouldDisableIdleTimer = delegate?.carplayManagerShouldDisableIdleTimer(self) {
871+
if let shouldDisableIdleTimer = delegate?.carPlayManagerShouldDisableIdleTimer(self) {
871872
UIApplication.shared.isIdleTimerDisabled = shouldDisableIdleTimer
872873
} else {
873874
UIApplication.shared.isIdleTimerDisabled = true
@@ -900,7 +901,7 @@ extension CarPlayManager {
900901

901902
eventsManager.sendCarPlayDisconnectEvent()
902903

903-
if let shouldDisableIdleTimer = delegate?.carplayManagerShouldDisableIdleTimer(self) {
904+
if let shouldDisableIdleTimer = delegate?.carPlayManagerShouldDisableIdleTimer(self) {
904905
UIApplication.shared.isIdleTimerDisabled = !shouldDisableIdleTimer
905906
} else {
906907
UIApplication.shared.isIdleTimerDisabled = false

Sources/MapboxNavigation/CarPlayManagerDelegate.swift

+19-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import MapboxMaps
99

1010
Implement this protocol and assign an instance to the `delegate` property of the shared instance of `CarPlayManager`.
1111

12-
If no delegate is set, a default built-in MapboxNavigationService will be created and used when a trip begins.
12+
If no delegate is set, a default built-in `MapboxNavigationService` will be created and used when a trip begins.
1313
*/
1414
@available(iOS 12.0, *)
1515
public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging {
@@ -63,7 +63,7 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging {
6363
- parameter desiredSimulationMode: The desired simulation mode to use.
6464
- returns: A navigation service that manages location updates along `route`.
6565
*/
66-
func carPlayManager(_ carPlayManager: CarPlayManager, navigationServiceAlong route: Route, routeIndex: Int, routeOptions: RouteOptions, desiredSimulationMode: SimulationMode) -> NavigationService
66+
func carPlayManager(_ carPlayManager: CarPlayManager, navigationServiceAlong route: Route, routeIndex: Int, routeOptions: RouteOptions, desiredSimulationMode: SimulationMode) -> NavigationService?
6767

6868
/**
6969
Called when the CarPlay manager fails to fetch a route.
@@ -84,7 +84,7 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging {
8484
- parameter trip: The trip that will be previewed.
8585
- returns: The actual trip to be previewed. This can be the same trip or a new/alternate trip if desired.
8686
*/
87-
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip) -> (CPTrip)
87+
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip) -> CPTrip
8888

8989
/**
9090
Offers the delegate the opportunity to customize a trip preview text configuration for a given trip.
@@ -94,7 +94,7 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging {
9494
- parameter previewTextConfiguration: The trip preview text configuration that will be presented alongside the trip.
9595
- returns: The actual preview text configuration to be presented alongside the trip.
9696
*/
97-
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip, with previewTextConfiguration: CPTripPreviewTextConfiguration) -> (CPTripPreviewTextConfiguration)
97+
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip, with previewTextConfiguration: CPTripPreviewTextConfiguration) -> CPTripPreviewTextConfiguration
9898

9999
/**
100100
Offers the delegate the opportunity to react to selection of a trip. Certain trips may have alternate route(s).
@@ -103,22 +103,22 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging {
103103
- parameter trip: The trip to begin navigating along.
104104
- parameter routeChoice: The possible route for the chosen trip.
105105
*/
106-
func carPlayManager(_ carPlayManager: CarPlayManager, selectedPreviewFor trip: CPTrip, using routeChoice: CPRouteChoice) -> ()
106+
func carPlayManager(_ carPlayManager: CarPlayManager, selectedPreviewFor trip: CPTrip, using routeChoice: CPRouteChoice)
107107

108108
/**
109109
Called when navigation begins so that the containing app can update accordingly.
110110

111111
- parameter carPlayManager: The CarPlay manager instance.
112112
- parameter service: The navigation service that has begun managing location updates for a navigation session.
113113
*/
114-
func carPlayManager(_ carPlayManager: CarPlayManager, didBeginNavigationWith service: NavigationService) -> ()
114+
func carPlayManager(_ carPlayManager: CarPlayManager, didBeginNavigationWith service: NavigationService)
115115

116116
/**
117117
Called when navigation ends so that the containing app can update accordingly.
118118

119119
- parameter carPlayManager: The CarPlay manager instance.
120120
*/
121-
func carPlayManagerDidEndNavigation(_ carPlayManager: CarPlayManager) -> ()
121+
func carPlayManagerDidEndNavigation(_ carPlayManager: CarPlayManager)
122122

123123
/**
124124
Called when the CarPlayManager detects the user arrives at the destination waypoint for a route leg.
@@ -137,7 +137,7 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging {
137137
- parameter carPlayManager: The CarPlay manager instance.
138138
- returns: A Boolean value indicating whether to disable idle timer when carplay is connected and enable when disconnected.
139139
*/
140-
func carplayManagerShouldDisableIdleTimer(_ carPlayManager: CarPlayManager) -> Bool
140+
func carPlayManagerShouldDisableIdleTimer(_ carPlayManager: CarPlayManager) -> Bool
141141

142142
/**
143143
Called when the CarPlayManager presents a new CarPlayNavigationViewController upon start of a navigation session.
@@ -147,7 +147,7 @@ public protocol CarPlayManagerDelegate: AnyObject, UnimplementedLogging {
147147
- parameter carPlayManager: The CarPlay manager instance.
148148
- parameter navigationViewController: The CarPlayNavigationViewController that was presented on the CarPlay display.
149149
*/
150-
func carPlayManager(_ carPlayManager: CarPlayManager, didPresent navigationViewController: CarPlayNavigationViewController) -> ()
150+
func carPlayManager(_ carPlayManager: CarPlayManager, didPresent navigationViewController: CarPlayNavigationViewController)
151151

152152
/**
153153
Tells the receiver that the `PointAnnotation` representing the final destination was added to either `CarPlayMapViewController` or `CarPlayNavigationViewController`.
@@ -189,6 +189,13 @@ public extension CarPlayManagerDelegate {
189189
return nil
190190
}
191191

192+
/**
193+
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
194+
*/
195+
func carPlayManager(_ carPlayManager: CarPlayManager, navigationServiceAlong route: Route, routeIndex: Int, routeOptions: RouteOptions, desiredSimulationMode: SimulationMode) -> NavigationService? {
196+
return nil
197+
}
198+
192199
/**
193200
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
194201
*/
@@ -200,15 +207,15 @@ public extension CarPlayManagerDelegate {
200207
/**
201208
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
202209
*/
203-
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip) -> (CPTrip) {
210+
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip) -> CPTrip {
204211
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
205212
return trip
206213
}
207214

208215
/**
209216
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
210217
*/
211-
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip, with previewTextConfiguration: CPTripPreviewTextConfiguration) -> (CPTripPreviewTextConfiguration) {
218+
func carPlayManager(_ carPlayManager: CarPlayManager, willPreview trip: CPTrip, with previewTextConfiguration: CPTripPreviewTextConfiguration) -> CPTripPreviewTextConfiguration {
212219
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
213220
return previewTextConfiguration
214221
}
@@ -245,7 +252,7 @@ public extension CarPlayManagerDelegate {
245252
/**
246253
`UnimplementedLogging` prints a warning to standard output the first time this method is called.
247254
*/
248-
func carplayManagerShouldDisableIdleTimer(_ carPlayManager: CarPlayManager) -> Bool {
255+
func carPlayManagerShouldDisableIdleTimer(_ carPlayManager: CarPlayManager) -> Bool {
249256
logUnimplemented(protocolType: CarPlayManagerDelegate.self, level: .debug)
250257
return false
251258
}

Tests/MapboxNavigationTests/MapViewTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MapViewTests: XCTestCase {
3939
let styleJSON: String = ValueConverter.toJson(forValue: styleJSONObject)
4040
XCTAssertFalse(styleJSON.isEmpty, "ValueConverter should create valid JSON string.")
4141

42-
let mapLoadingErrorExpectation = expectation(description: "Style loaded expectation")
42+
let mapLoadingErrorExpectation = expectation(description: "Map loading error expectation")
4343

4444
mapView.mapboxMap.onNext(.mapLoadingError, handler: { event in
4545
mapLoadingErrorExpectation.fulfill()
@@ -109,15 +109,15 @@ class MapViewTests: XCTestCase {
109109
let styleJSON: String = ValueConverter.toJson(forValue: styleJSONObject)
110110
XCTAssertFalse(styleJSON.isEmpty, "ValueConverter should create valid JSON string.")
111111

112-
let mapLoadingErrorExpectation = expectation(description: "Style loaded expectation")
112+
let mapLoadingErrorExpectation = expectation(description: "Map loading error expectation")
113113

114114
mapView.mapboxMap.onNext(.mapLoadingError, handler: { event in
115115
mapLoadingErrorExpectation.fulfill()
116116
})
117117

118118
mapView.mapboxMap.loadStyleJSON(styleJSON)
119119

120-
wait(for: [mapLoadingErrorExpectation], timeout: 1.0)
120+
wait(for: [mapLoadingErrorExpectation], timeout: 10.0)
121121

122122
XCTAssertEqual(mapView.mapboxMap.style.allSourceIdentifiers.count,
123123
1,

0 commit comments

Comments
 (0)