Skip to content

Commit bc4544a

Browse files
author
Siarhei Fedartsou
committed
Implement FixLocation.provider field based on CLSourceInformation
1 parent 386f34a commit bc4544a

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

Sources/MapboxCoreNavigation/FixLocation.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ import CoreLocation
22
import Foundation
33
import MapboxNavigationNative
44

5-
extension FixLocation {
65

6+
extension FixLocation {
77
convenience init(_ location: CLLocation, isMock: Bool = false) {
88
var bearingAccuracy: NSNumber? = nil
99
if #available(iOS 13.4, *) {
1010
bearingAccuracy = location.courseAccuracy >= 0 ? location.courseAccuracy as NSNumber : nil
1111
}
12+
13+
var provider: String? = nil
14+
#if compiler(>=5.5)
15+
if #available(iOS 15.0, *) {
16+
if let sourceInformation = location.sourceInformation {
17+
// in some scenarios we store this information to history files, so to save space there, we use "short" names and 1/0 instead of true/false
18+
let isSimulated = sourceInformation.isSimulatedBySoftware ? 1 : 0
19+
let isProducedByAccessory = sourceInformation.isProducedByAccessory ? 1 : 0
20+
21+
provider = "sim:\(isSimulated),acc:\(isProducedByAccessory)"
22+
}
23+
}
24+
#endif
1225

1326
self.init(coordinate: location.coordinate,
1427
monotonicTimestampNanoseconds: Int64(location.timestamp.nanosecondsSince1970),
@@ -17,7 +30,7 @@ extension FixLocation {
1730
bearing: location.course >= 0 ? location.course as NSNumber : nil,
1831
altitude: location.altitude as NSNumber,
1932
accuracyHorizontal: location.horizontalAccuracy >= 0 ? location.horizontalAccuracy as NSNumber : nil,
20-
provider: nil,
33+
provider: provider,
2134
bearingAccuracy: bearingAccuracy,
2235
speedAccuracy: location.speedAccuracy >= 0 ? location.speedAccuracy as NSNumber : nil,
2336
verticalAccuracy: location.verticalAccuracy >= 0 ? location.verticalAccuracy as NSNumber : nil,

Tests/MapboxCoreNavigationTests/CLLocationTests.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,25 @@ class CLLocationTests: TestCase {
9292
speedAccuracy: speedAccuracy,
9393
timestamp: timestamp)
9494
}
95-
95+
#if compiler(>=5.5)
96+
if #available(iOS 15.0, *) {
97+
let sourceInfo = CLLocationSourceInformation(
98+
softwareSimulationState: true,
99+
andExternalAccessoryState: false
100+
)
101+
location = CLLocation(coordinate: coordinate,
102+
altitude: altitude,
103+
horizontalAccuracy: horizontalAccuracy,
104+
verticalAccuracy: verticalAccuracy,
105+
course: bearing,
106+
courseAccuracy: bearingAccuracy,
107+
speed: speed,
108+
speedAccuracy: speedAccuracy,
109+
timestamp: timestamp,
110+
sourceInfo: sourceInfo)
111+
}
112+
#endif
113+
96114
let fixLocation = FixLocation(location)
97115

98116
XCTAssertEqual(fixLocation.coordinate.latitude, coordinate.latitude)
@@ -108,6 +126,11 @@ class CLLocationTests: TestCase {
108126
XCTAssertEqual(fixLocation.bearingAccuracy?.doubleValue, bearingAccuracy)
109127
XCTAssertEqual(fixLocation.speedAccuracy?.doubleValue, speedAccuracy)
110128
}
129+
#if compiler(>=5.5)
130+
if #available(iOS 15.0, *) {
131+
XCTAssertEqual(fixLocation.provider, "sim:1,acc:0")
132+
}
133+
#endif
111134
}
112135
}
113136

0 commit comments

Comments
 (0)