@capacitor/geolocation 7.1.1 → 7.1.2

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", branch: "main")
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.getLong("timeout", 10000) ?: 10000
330
- val maximumAge = call.getLong("maximumAge", 0) ?: 0
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.getLong("minimumUpdateInterval", 5000) ?: 5000
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
  }
@@ -18,7 +18,8 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
18
18
  private var locationService: (any IONGLOCService)?
19
19
  private var cancellables = Set<AnyCancellable>()
20
20
  private var callbackManager: GeolocationCallbackManager?
21
- private var isInitialised: Bool = false
21
+ private var statusInitialized = false
22
+ private var locationInitialized: Bool = false
22
23
 
23
24
  override public func load() {
24
25
  self.locationService = IONGLOCManagerWrapper()
@@ -83,12 +84,13 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
83
84
 
84
85
  private extension GeolocationPlugin {
85
86
  func shouldSetupBindings() {
86
- guard !isInitialised else { return }
87
- isInitialised = true
88
- setupBindings()
87
+ bindAuthorisationStatusPublisher()
88
+ bindLocationPublisher()
89
89
  }
90
90
 
91
- func setupBindings() {
91
+ func bindAuthorisationStatusPublisher() {
92
+ guard !statusInitialized else { return }
93
+ statusInitialized = true
92
94
  locationService?.authorisationStatusPublisher
93
95
  .sink(receiveValue: { [weak self] status in
94
96
  guard let self else { return }
@@ -106,10 +108,16 @@ private extension GeolocationPlugin {
106
108
  }
107
109
  })
108
110
  .store(in: &cancellables)
111
+ }
109
112
 
113
+ func bindLocationPublisher() {
114
+ guard !locationInitialized else { return }
115
+ locationInitialized = true
110
116
  locationService?.currentLocationPublisher
111
117
  .sink(receiveCompletion: { [weak self] completion in
112
118
  if case .failure(let error) = completion {
119
+ // publisher should be re-observed in the next plugin call
120
+ self?.locationInitialized = false
113
121
  print("An error was found while retrieving the location: \(error)")
114
122
  self?.callbackManager?.sendError(.positionUnavailable)
115
123
  }
@@ -128,10 +136,10 @@ private extension GeolocationPlugin {
128
136
 
129
137
  func checkIfLocationServicesAreEnabled(_ call: CAPPluginCall? = nil) -> Bool {
130
138
  guard locationService?.areLocationServicesEnabled() == true else {
131
- call.map { callbackManager?.sendError($0, error: .locationServicesDisabled) }
132
- ?? callbackManager?.sendError(.locationServicesDisabled)
133
- return false
134
- }
139
+ call.map { callbackManager?.sendError($0, error: .locationServicesDisabled) }
140
+ ?? callbackManager?.sendError(.locationServicesDisabled)
141
+ return false
142
+ }
135
143
  return true
136
144
  }
137
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/geolocation",
3
- "version": "7.1.1",
3
+ "version": "7.1.2",
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",