@capacitor/geolocation 7.1.2 → 7.1.3
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Capacitor
|
|
2
2
|
import IONGeolocationLib
|
|
3
|
+
import UIKit
|
|
3
4
|
|
|
4
5
|
import Combine
|
|
5
6
|
|
|
@@ -17,6 +18,7 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
17
18
|
|
|
18
19
|
private var locationService: (any IONGLOCService)?
|
|
19
20
|
private var cancellables = Set<AnyCancellable>()
|
|
21
|
+
private var locationCancellable: AnyCancellable?
|
|
20
22
|
private var callbackManager: GeolocationCallbackManager?
|
|
21
23
|
private var statusInitialized = false
|
|
22
24
|
private var locationInitialized: Bool = false
|
|
@@ -24,6 +26,30 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
24
26
|
override public func load() {
|
|
25
27
|
self.locationService = IONGLOCManagerWrapper()
|
|
26
28
|
self.callbackManager = .init(capacitorBridge: bridge)
|
|
29
|
+
|
|
30
|
+
NotificationCenter.default.addObserver(
|
|
31
|
+
self,
|
|
32
|
+
selector: #selector(appDidBecomeActive),
|
|
33
|
+
name: UIApplication.didBecomeActiveNotification,
|
|
34
|
+
object: nil
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@objc private func appDidBecomeActive() {
|
|
39
|
+
if let watchCallbacksEmpty = callbackManager?.watchCallbacks.isEmpty, !watchCallbacksEmpty {
|
|
40
|
+
print("App became active. Restarting location monitoring for watch callbacks.")
|
|
41
|
+
locationCancellable?.cancel()
|
|
42
|
+
locationCancellable = nil
|
|
43
|
+
locationInitialized = false
|
|
44
|
+
|
|
45
|
+
locationService?.stopMonitoringLocation()
|
|
46
|
+
locationService?.startMonitoringLocation()
|
|
47
|
+
bindLocationPublisher()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
deinit {
|
|
52
|
+
NotificationCenter.default.removeObserver(self)
|
|
27
53
|
}
|
|
28
54
|
|
|
29
55
|
@objc func getCurrentPosition(_ call: CAPPluginCall) {
|
|
@@ -49,6 +75,9 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
49
75
|
|
|
50
76
|
if (callbackManager?.watchCallbacks.isEmpty) ?? false {
|
|
51
77
|
locationService?.stopMonitoringLocation()
|
|
78
|
+
locationCancellable?.cancel()
|
|
79
|
+
locationCancellable = nil
|
|
80
|
+
locationInitialized = false
|
|
52
81
|
}
|
|
53
82
|
|
|
54
83
|
callbackManager?.sendSuccess(call)
|
|
@@ -113,18 +142,24 @@ private extension GeolocationPlugin {
|
|
|
113
142
|
func bindLocationPublisher() {
|
|
114
143
|
guard !locationInitialized else { return }
|
|
115
144
|
locationInitialized = true
|
|
116
|
-
locationService?.currentLocationPublisher
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
print("
|
|
145
|
+
locationCancellable = locationService?.currentLocationPublisher
|
|
146
|
+
.catch { [weak self] error -> AnyPublisher<IONGLOCPositionModel, Never> in
|
|
147
|
+
print("An error was found while retrieving the location: \(error)")
|
|
148
|
+
|
|
149
|
+
if case IONGLOCLocationError.locationUnavailable = error {
|
|
150
|
+
print("Location unavailable (likely due to backgrounding). Keeping watch callbacks alive.")
|
|
122
151
|
self?.callbackManager?.sendError(.positionUnavailable)
|
|
152
|
+
return Empty<IONGLOCPositionModel, Never>()
|
|
153
|
+
.eraseToAnyPublisher()
|
|
154
|
+
} else {
|
|
155
|
+
self?.callbackManager?.sendError(.positionUnavailable)
|
|
156
|
+
return Empty<IONGLOCPositionModel, Never>()
|
|
157
|
+
.eraseToAnyPublisher()
|
|
123
158
|
}
|
|
124
|
-
}
|
|
159
|
+
}
|
|
160
|
+
.sink(receiveValue: { [weak self] position in
|
|
125
161
|
self?.callbackManager?.sendSuccess(with: position)
|
|
126
162
|
})
|
|
127
|
-
.store(in: &cancellables)
|
|
128
163
|
}
|
|
129
164
|
|
|
130
165
|
func requestLocationAuthorisation(type requestType: IONGLOCAuthorisationRequestType) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/geolocation",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.3",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"prepublishOnly": "npm run build"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@capacitor/synapse": "^1.0.
|
|
49
|
+
"@capacitor/synapse": "^1.0.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@capacitor/android": "next",
|