@capacitor/geolocation 7.1.1 → 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.
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ionic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
CHANGED
|
@@ -10,7 +10,7 @@ let package = Package(
|
|
|
10
10
|
targets: ["GeolocationPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git",
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
|
|
14
14
|
],
|
|
15
15
|
targets: [
|
|
16
16
|
.binaryTarget(
|
|
@@ -326,13 +326,16 @@ class GeolocationPlugin : Plugin() {
|
|
|
326
326
|
* @return IONGLOCLocationOptions object
|
|
327
327
|
*/
|
|
328
328
|
private fun createOptions(call: PluginCall): IONGLOCLocationOptions {
|
|
329
|
-
val timeout = call.
|
|
330
|
-
val maximumAge = call.
|
|
329
|
+
val timeout = call.getNumber("timeout", 10000)
|
|
330
|
+
val maximumAge = call.getNumber("maximumAge", 0)
|
|
331
331
|
val enableHighAccuracy = call.getBoolean("enableHighAccuracy", false) ?: false
|
|
332
|
-
val minimumUpdateInterval = call.
|
|
332
|
+
val minimumUpdateInterval = call.getNumber("minimumUpdateInterval", 5000)
|
|
333
333
|
|
|
334
334
|
val locationOptions = IONGLOCLocationOptions(timeout, maximumAge, enableHighAccuracy, minimumUpdateInterval)
|
|
335
335
|
|
|
336
336
|
return locationOptions
|
|
337
337
|
}
|
|
338
|
+
|
|
339
|
+
private fun PluginCall.getNumber(name: String, defaultValue: Long): Long =
|
|
340
|
+
getLong(name) ?: getInt(name)?.toLong() ?: defaultValue
|
|
338
341
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Capacitor
|
|
2
2
|
import IONGeolocationLib
|
|
3
|
+
import UIKit
|
|
3
4
|
|
|
4
5
|
import Combine
|
|
5
6
|
|
|
@@ -17,12 +18,38 @@ 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
|
-
private var
|
|
23
|
+
private var statusInitialized = false
|
|
24
|
+
private var locationInitialized: Bool = false
|
|
22
25
|
|
|
23
26
|
override public func load() {
|
|
24
27
|
self.locationService = IONGLOCManagerWrapper()
|
|
25
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)
|
|
26
53
|
}
|
|
27
54
|
|
|
28
55
|
@objc func getCurrentPosition(_ call: CAPPluginCall) {
|
|
@@ -48,6 +75,9 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
48
75
|
|
|
49
76
|
if (callbackManager?.watchCallbacks.isEmpty) ?? false {
|
|
50
77
|
locationService?.stopMonitoringLocation()
|
|
78
|
+
locationCancellable?.cancel()
|
|
79
|
+
locationCancellable = nil
|
|
80
|
+
locationInitialized = false
|
|
51
81
|
}
|
|
52
82
|
|
|
53
83
|
callbackManager?.sendSuccess(call)
|
|
@@ -83,12 +113,13 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
83
113
|
|
|
84
114
|
private extension GeolocationPlugin {
|
|
85
115
|
func shouldSetupBindings() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
setupBindings()
|
|
116
|
+
bindAuthorisationStatusPublisher()
|
|
117
|
+
bindLocationPublisher()
|
|
89
118
|
}
|
|
90
119
|
|
|
91
|
-
func
|
|
120
|
+
func bindAuthorisationStatusPublisher() {
|
|
121
|
+
guard !statusInitialized else { return }
|
|
122
|
+
statusInitialized = true
|
|
92
123
|
locationService?.authorisationStatusPublisher
|
|
93
124
|
.sink(receiveValue: { [weak self] status in
|
|
94
125
|
guard let self else { return }
|
|
@@ -106,17 +137,29 @@ private extension GeolocationPlugin {
|
|
|
106
137
|
}
|
|
107
138
|
})
|
|
108
139
|
.store(in: &cancellables)
|
|
140
|
+
}
|
|
109
141
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
142
|
+
func bindLocationPublisher() {
|
|
143
|
+
guard !locationInitialized else { return }
|
|
144
|
+
locationInitialized = true
|
|
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.")
|
|
151
|
+
self?.callbackManager?.sendError(.positionUnavailable)
|
|
152
|
+
return Empty<IONGLOCPositionModel, Never>()
|
|
153
|
+
.eraseToAnyPublisher()
|
|
154
|
+
} else {
|
|
114
155
|
self?.callbackManager?.sendError(.positionUnavailable)
|
|
156
|
+
return Empty<IONGLOCPositionModel, Never>()
|
|
157
|
+
.eraseToAnyPublisher()
|
|
115
158
|
}
|
|
116
|
-
}
|
|
159
|
+
}
|
|
160
|
+
.sink(receiveValue: { [weak self] position in
|
|
117
161
|
self?.callbackManager?.sendSuccess(with: position)
|
|
118
162
|
})
|
|
119
|
-
.store(in: &cancellables)
|
|
120
163
|
}
|
|
121
164
|
|
|
122
165
|
func requestLocationAuthorisation(type requestType: IONGLOCAuthorisationRequestType) {
|
|
@@ -128,10 +171,10 @@ private extension GeolocationPlugin {
|
|
|
128
171
|
|
|
129
172
|
func checkIfLocationServicesAreEnabled(_ call: CAPPluginCall? = nil) -> Bool {
|
|
130
173
|
guard locationService?.areLocationServicesEnabled() == true else {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
174
|
+
call.map { callbackManager?.sendError($0, error: .locationServicesDisabled) }
|
|
175
|
+
?? callbackManager?.sendError(.locationServicesDisabled)
|
|
176
|
+
return false
|
|
177
|
+
}
|
|
135
178
|
return true
|
|
136
179
|
}
|
|
137
180
|
|
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",
|