@capacitor/geolocation 7.1.5-dev.3 → 7.1.5-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -216,10 +216,10 @@ private extension GeolocationPlugin {
|
|
|
216
216
|
callbackManager?.sendRequestPermissionsSuccess(Constants.AuthorisationStatus.Status.granted)
|
|
217
217
|
}
|
|
218
218
|
if shouldRequestCurrentPosition {
|
|
219
|
-
locationService?.requestSingleLocation(timeout: self.timeout)
|
|
219
|
+
locationService?.requestSingleLocation(options: IONGLOCRequestOptionsModel(timeout: self.timeout))
|
|
220
220
|
}
|
|
221
221
|
if shouldRequestLocationMonitoring {
|
|
222
|
-
locationService?.startMonitoringLocation(timeout: self.timeout)
|
|
222
|
+
locationService?.startMonitoringLocation(options: IONGLOCRequestOptionsModel(timeout: self.timeout))
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
|
package/ios/Sources/GeolocationPlugin/IONGeolocationLib/Publishers/IONGLOCManagerWrapper.swift
CHANGED
|
@@ -40,6 +40,11 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
|
|
|
40
40
|
|
|
41
41
|
private var isMonitoringLocation = false
|
|
42
42
|
|
|
43
|
+
// Flag used to indicate that the location request has timed out.
|
|
44
|
+
// When `true`, the wrapper ignores any location updates received from CLLocationManager.
|
|
45
|
+
// This prevents "stale" or "ghost" events from being sent to subscribers after the timeout has occurred.
|
|
46
|
+
private var timeoutTriggered = false
|
|
47
|
+
|
|
43
48
|
public init(locationManager: CLLocationManager = .init(), servicesChecker: IONGLOCServicesChecker = IONGLOCServicesValidator()) {
|
|
44
49
|
self.locationManager = locationManager
|
|
45
50
|
self.servicesChecker = servicesChecker
|
|
@@ -52,14 +57,19 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
|
|
|
52
57
|
public func requestAuthorisation(withType authorisationType: IONGLOCAuthorisationRequestType) {
|
|
53
58
|
authorisationType.requestAuthorization(using: locationManager)
|
|
54
59
|
}
|
|
55
|
-
|
|
60
|
+
|
|
56
61
|
public func startMonitoringLocation(options: IONGLOCRequestOptionsModel) {
|
|
62
|
+
timeoutTriggered = false
|
|
57
63
|
isMonitoringLocation = true
|
|
58
|
-
self.startTimer(timeout: options.timeout)
|
|
59
64
|
locationManager.startUpdatingLocation()
|
|
65
|
+
self.startTimer(timeout: options.timeout)
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
public func startMonitoringLocation() {
|
|
69
|
+
guard !timeoutTriggered else {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
63
73
|
isMonitoringLocation = true
|
|
64
74
|
locationManager.startUpdatingLocation()
|
|
65
75
|
}
|
|
@@ -70,6 +80,7 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
|
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
public func requestSingleLocation(options: IONGLOCRequestOptionsModel) {
|
|
83
|
+
timeoutTriggered = false
|
|
73
84
|
// If monitoring is active meaning the location service is already running
|
|
74
85
|
// and calling .requestLocation() will not trigger a new location update,
|
|
75
86
|
// we can just return the current location.
|
|
@@ -77,8 +88,9 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
|
|
|
77
88
|
currentLocationForceSubject.send(location)
|
|
78
89
|
return
|
|
79
90
|
}
|
|
80
|
-
|
|
91
|
+
|
|
81
92
|
self.locationManager.requestLocation()
|
|
93
|
+
self.startTimer(timeout: options.timeout)
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
private func startTimer(timeout: Int) {
|
|
@@ -88,7 +100,14 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
|
|
|
88
100
|
.delay(for: .milliseconds(timeout), scheduler: DispatchQueue.main)
|
|
89
101
|
.sink { [weak self] _ in
|
|
90
102
|
guard let self = self else { return }
|
|
103
|
+
self.timeoutTriggered = true
|
|
91
104
|
self.locationTimeoutSubject.send(.timeout)
|
|
105
|
+
|
|
106
|
+
if self.isMonitoringLocation {
|
|
107
|
+
self.isMonitoringLocation = false
|
|
108
|
+
self.stopMonitoringLocation()
|
|
109
|
+
}
|
|
110
|
+
|
|
92
111
|
self.timeoutCancellable?.cancel()
|
|
93
112
|
self.timeoutCancellable = nil
|
|
94
113
|
}
|
|
@@ -110,8 +129,12 @@ extension IONGLOCManagerWrapper: CLLocationManagerDelegate {
|
|
|
110
129
|
public func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
|
111
130
|
authorisationStatus = manager.currentAuthorisationValue
|
|
112
131
|
}
|
|
113
|
-
|
|
132
|
+
|
|
114
133
|
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
|
134
|
+
guard !timeoutTriggered else {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
115
138
|
timeoutCancellable?.cancel()
|
|
116
139
|
timeoutCancellable = nil
|
|
117
140
|
guard let latestLocation = locations.last else {
|
|
@@ -120,7 +143,7 @@ extension IONGLOCManagerWrapper: CLLocationManagerDelegate {
|
|
|
120
143
|
}
|
|
121
144
|
currentLocation = IONGLOCPositionModel.create(from: latestLocation)
|
|
122
145
|
}
|
|
123
|
-
|
|
146
|
+
|
|
124
147
|
public func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
|
|
125
148
|
timeoutCancellable?.cancel()
|
|
126
149
|
timeoutCancellable = nil
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/geolocation",
|
|
3
|
-
"version": "7.1.5-dev.
|
|
3
|
+
"version": "7.1.5-dev.5",
|
|
4
4
|
"description": "The Geolocation API provides simple methods for getting and tracking the current position of the device using GPS, along with altitude, heading, and speed information if available.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|