Skip to content

Commit f05868d

Browse files
committed
Fixed ProfileIdentifier comparison for the custom profile identifiers, so that route refresh is enabled for custom automobileAvoidingTraffic profiles (#4779)
1 parent 33573b1 commit f05868d

File tree

10 files changed

+40
-33
lines changed

10 files changed

+40
-33
lines changed

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "23.11.4"
22
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-navigation-native/MapboxNavigationNative.xcframework.json" "206.1.0"
3-
github "mapbox/mapbox-directions-swift" "v2.14.0"
3+
github "mapbox/mapbox-directions-swift" "v2.14.1"
44
github "mapbox/turf-swift" "v2.8.0"
55
github "mattgallagher/CwlPreconditionTesting" "2.2.2"
66
github "pointfreeco/swift-snapshot-testing" "1.9.0"

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
@@ -22,7 +22,7 @@ let package = Package(
2222
)
2323
],
2424
dependencies: [
25-
.package(name: "MapboxDirections", url: "https://github.com/mapbox/mapbox-directions-swift.git", from: "2.14.0"),
25+
.package(name: "MapboxDirections", url: "https://github.com/mapbox/mapbox-directions-swift.git", from: "2.14.1"),
2626
.package(name: "MapboxNavigationNative", url: "https://github.com/mapbox/mapbox-navigation-native-ios.git", from: "206.0.1"),
2727
.package(name: "MapboxMaps", url: "https://github.com/mapbox/mapbox-maps-ios.git", from: "10.19.0"),
2828
.package(name: "Solar", url: "https://github.com/ceeK/Solar.git", from: "3.0.0"),

Sources/MapboxCoreNavigation/LegacyRouteController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa
272272
let options = indexedRouteResponse.validatedRouteOptions
273273
self.routeProgress = RouteProgress(route: indexedRouteResponse.currentRoute!, options: options)
274274
self.dataSource = source
275-
self.refreshesRoute = options.profileIdentifier == .automobileAvoidingTraffic && options.refreshingEnabled
275+
self.refreshesRoute = options.profileIdentifier.isAutomobileAvoidingTraffic && options.refreshingEnabled
276276
UIDevice.current.isBatteryMonitoringEnabled = true
277277

278278
super.init()

Sources/MapboxCoreNavigation/MapboxRoutingProvider.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,29 @@ public class MapboxRoutingProvider: RoutingProvider {
468468
}
469469

470470
extension ProfileIdentifier {
471-
var nativeProfile: RoutingProfile {
472-
var mode: RoutingMode
471+
var isCycling: Bool {
472+
rawValue.hasSuffix("cycling")
473+
}
474+
475+
var mode: RoutingMode {
473476
switch self {
474-
case .automobile:
475-
mode = .driving
476-
case .automobileAvoidingTraffic:
477-
mode = .drivingTraffic
478-
case .cycling:
479-
mode = .cycling
480-
case .walking:
481-
mode = .walking
477+
case _ where isAutomobile:
478+
return .driving
479+
case _ where isAutomobileAvoidingTraffic:
480+
return .drivingTraffic
481+
case _ where isCycling:
482+
return .cycling
483+
case _ where isWalking:
484+
return .walking
482485
default:
483-
mode = .driving
486+
return .driving
484487
}
485-
return RoutingProfile(mode: mode, account: "mapbox")
488+
}
489+
490+
var nativeProfile: RoutingProfile {
491+
let accountComponent = rawValue.split(separator: "/").first.map(String.init) ?? ""
492+
let account = accountComponent.isEmpty ? "mapbox" : accountComponent
493+
return RoutingProfile(mode: mode, account: account)
486494
}
487495
}
488496

Sources/MapboxCoreNavigation/NavigationRouteOptions.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ open class NavigationRouteOptions: RouteOptions, OptimizedForNavigation {
2626
queryItems: queryItems)
2727
includesAlternativeRoutes = true
2828
attributeOptions = [.expectedTravelTime, .maximumSpeedLimit]
29-
if profileIdentifier == .automobileAvoidingTraffic {
30-
attributeOptions.update(with: .numericCongestionLevel)
31-
}
3229
includesExitRoundaboutManeuver = true
33-
if profileIdentifier == .automobileAvoidingTraffic {
30+
if let profileIdentifier, profileIdentifier.isAutomobileAvoidingTraffic {
31+
attributeOptions.update(with: .numericCongestionLevel)
3432
refreshingEnabled = true
3533
}
3634

@@ -89,11 +87,13 @@ open class NavigationMatchOptions: MatchOptions, OptimizedForNavigation {
8987
profileIdentifier: profileIdentifier,
9088
queryItems: queryItems)
9189
attributeOptions = [.expectedTravelTime]
92-
if profileIdentifier == .automobileAvoidingTraffic {
93-
attributeOptions.update(with: .numericCongestionLevel)
94-
}
95-
if profileIdentifier == .automobile || profileIdentifier == .automobileAvoidingTraffic {
96-
attributeOptions.insert(.maximumSpeedLimit)
90+
if let profileIdentifier {
91+
if profileIdentifier.isAutomobileAvoidingTraffic {
92+
attributeOptions.update(with: .numericCongestionLevel)
93+
}
94+
if profileIdentifier.isAutomobile || profileIdentifier.isAutomobileAvoidingTraffic {
95+
attributeOptions.insert(.maximumSpeedLimit)
96+
}
9797
}
9898

9999
optimizeForNavigation()

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ open class RouteController: NSObject {
676676
let options = indexedRouteResponse.validatedRouteOptions
677677

678678
self.routeProgress = RouteProgress(route: indexedRouteResponse.currentRoute!, options: options)
679-
self.refreshesRoute = isRouteOptions && options.profileIdentifier == .automobileAvoidingTraffic && options.refreshingEnabled
679+
self.refreshesRoute = isRouteOptions && options.profileIdentifier.isAutomobileAvoidingTraffic && options.refreshingEnabled
680680

681681
super.init()
682682

Sources/MapboxCoreNavigation/RouteOptions.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import MapboxDirections
33

44
extension RouteOptions {
55
internal var activityType: CLActivityType {
6-
switch self.profileIdentifier {
7-
case .cycling, .walking:
6+
if profileIdentifier.isCycling || profileIdentifier.isWalking {
87
return .fitness
9-
default:
10-
return .otherNavigation
118
}
9+
return .otherNavigation
1210
}
1311

1412
/**

Sources/MapboxCoreNavigation/Router.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ extension InternalRouter where Self: Router {
501501
let options = progress.reroutingOptions(from: origin)
502502

503503
// https://github.com/mapbox/mapbox-navigation-ios/issues/3966
504-
if isRerouting && (options.profileIdentifier == .automobile || options.profileIdentifier == .automobileAvoidingTraffic) {
504+
let profile = options.profileIdentifier
505+
if isRerouting && (profile.isAutomobile || profile.isAutomobileAvoidingTraffic) {
505506
options.initialManeuverAvoidanceRadius = initialManeuverAvoidanceRadius * origin.speed
506507
}
507508

Tests/CocoaPodsTest/PodInstall/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ SPEC CHECKSUMS:
6565

6666
PODFILE CHECKSUM: bde8103af0e9b326531ee57cf1fa935cbd5f2e18
6767

68-
COCOAPODS: 1.12.0
68+
COCOAPODS: 1.15.2

0 commit comments

Comments
 (0)