@capacitor/geolocation 8.0.0-next.3 → 8.0.0-next.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.
@@ -13,6 +13,6 @@ Pod::Spec.new do |s|
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'IONGeolocationLib', spec='1.0.1'
16
+ s.dependency 'IONGeolocationLib', spec='2.0.0'
17
17
  s.swift_version = '5.1'
18
18
  end
package/Package.swift CHANGED
@@ -11,7 +11,7 @@ let package = Package(
11
11
  ],
12
12
  dependencies: [
13
13
  .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0"),
14
- .package(url: "https://github.com/ionic-team/ion-ios-geolocation.git", from: "1.0.2")
14
+ .package(url: "https://github.com/ionic-team/ion-ios-geolocation.git", from: "2.0.0")
15
15
  ],
16
16
  targets: [
17
17
  .target(
package/README.md CHANGED
@@ -238,7 +238,7 @@ The following table list all the plugin errors:
238
238
  | OS-PLUG-GLOC-0007 | Android, iOS | Location services are not enabled. |
239
239
  | OS-PLUG-GLOC-0008 | iOS | Application's use of location services was restricted. |
240
240
  | OS-PLUG-GLOC-0009 | Android | Request to enable location was denied. |
241
- | OS-PLUG-GLOC-0010 | Android | Could not obtain location in time. Try with a higher timeout. |
241
+ | OS-PLUG-GLOC-0010 | Android, iOS | Could not obtain location in time. Try with a higher timeout. |
242
242
  | OS-PLUG-GLOC-0011 | Android | Timeout needs to be a positive value. |
243
243
  | OS-PLUG-GLOC-0012 | Android | WatchId not found. |
244
244
  | OS-PLUG-GLOC-0013 | Android | WatchId needs to be provided. |
@@ -7,13 +7,13 @@ ext {
7
7
  }
8
8
 
9
9
  buildscript {
10
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.25'
10
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '2.2.20'
11
11
  repositories {
12
12
  google()
13
13
  mavenCentral()
14
14
  }
15
15
  dependencies {
16
- classpath 'com.android.tools.build:gradle:8.7.2'
16
+ classpath 'com.android.tools.build:gradle:8.13.0'
17
17
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
18
18
  }
19
19
  }
@@ -22,8 +22,8 @@ apply plugin: 'com.android.library'
22
22
  apply plugin: 'kotlin-android'
23
23
 
24
24
  android {
25
- namespace "com.capacitorjs.plugins.geolocation"
26
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
25
+ namespace = "com.capacitorjs.plugins.geolocation"
26
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
27
27
  defaultConfig {
28
28
  minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
29
29
  targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
@@ -38,7 +38,7 @@ android {
38
38
  }
39
39
  }
40
40
  lintOptions {
41
- abortOnError false
41
+ abortOnError = false
42
42
  }
43
43
  compileOptions {
44
44
  sourceCompatibility JavaVersion.VERSION_21
@@ -24,6 +24,7 @@ final class GeolocationCallbackManager {
24
24
  private(set) var requestPermissionsCallbacks: [CAPPluginCall]
25
25
  private(set) var locationCallbacks: [CAPPluginCall]
26
26
  private(set) var watchCallbacks: [String: CAPPluginCall]
27
+ private(set) var timeout: Int?
27
28
  private let capacitorBridge: CAPBridgeProtocol?
28
29
 
29
30
  private var allCallbackGroups: [GeolocationCallbackGroup] {
@@ -52,11 +53,15 @@ final class GeolocationCallbackManager {
52
53
  func addLocationCallback(capacitorCall call: CAPPluginCall) {
53
54
  capacitorBridge?.saveCall(call)
54
55
  locationCallbacks.append(call)
56
+ let timeout = call.getInt(Constants.Arguments.timeout)
57
+ self.timeout = timeout
55
58
  }
56
59
 
57
60
  func addWatchCallback(_ watchId: String, capacitorCall call: CAPPluginCall) {
58
61
  capacitorBridge?.saveCall(call)
59
62
  watchCallbacks[watchId] = call
63
+ let timeout = call.getInt(Constants.Arguments.timeout)
64
+ self.timeout = timeout
60
65
  }
61
66
 
62
67
  func clearRequestPermissionsCallbacks() {
@@ -109,6 +114,10 @@ final class GeolocationCallbackManager {
109
114
 
110
115
  func sendError(_ error: GeolocationError) {
111
116
  createPluginResult(status: .error(error.toCodeMessagePair()))
117
+
118
+ if case .timeout = error {
119
+ watchCallbacks.keys.forEach { clearWatchCallbackIfExists($0) }
120
+ }
112
121
  }
113
122
  }
114
123
 
@@ -2,6 +2,7 @@ enum Constants {
2
2
  enum Arguments {
3
3
  static let enableHighAccuracy = "enableHighAccuracy"
4
4
  static let id = "id"
5
+ static let timeout = "timeout"
5
6
  }
6
7
 
7
8
  enum AuthorisationStatus {
@@ -10,6 +10,7 @@ enum GeolocationError: Error {
10
10
  case permissionRestricted
11
11
  case positionUnavailable
12
12
  case inputArgumentsIssue(target: GeolocationMethod)
13
+ case timeout
13
14
 
14
15
  func toCodeMessagePair() -> (String, String) {
15
16
  ("OS-PLUG-GLOC-\(String(format: "%04d", code))", description)
@@ -29,16 +30,18 @@ private extension GeolocationError {
29
30
  case .watchPosition: 5
30
31
  case .clearWatch: 6
31
32
  }
33
+ case .timeout: 10
32
34
  }
33
35
  }
34
36
 
35
37
  var description: String {
36
38
  switch self {
37
- case .positionUnavailable: "There was en error trying to obtain the location."
39
+ case .positionUnavailable: "There was an error trying to obtain the location."
38
40
  case .permissionDenied: "Location permission request was denied."
39
41
  case .locationServicesDisabled: "Location services are not enabled."
40
42
  case .permissionRestricted: "Application's use of location services was restricted."
41
43
  case .inputArgumentsIssue(let target): "The '\(target.rawValue)' input parameters aren't valid."
44
+ case .timeout: "Could not obtain location in time. Try with a higher timeout."
42
45
  }
43
46
  }
44
47
  }
@@ -1,7 +1,6 @@
1
1
  import Capacitor
2
2
  import IONGeolocationLib
3
3
  import UIKit
4
-
5
4
  import Combine
6
5
 
7
6
  @objc(GeolocationPlugin)
@@ -19,6 +18,7 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
19
18
  private var locationService: (any IONGLOCService)?
20
19
  private var cancellables = Set<AnyCancellable>()
21
20
  private var locationCancellable: AnyCancellable?
21
+ private var timeoutCancellable: AnyCancellable?
22
22
  private var callbackManager: GeolocationCallbackManager?
23
23
  private var statusInitialized = false
24
24
  private var locationInitialized: Bool = false
@@ -26,7 +26,7 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
26
26
  override public func load() {
27
27
  self.locationService = IONGLOCManagerWrapper()
28
28
  self.callbackManager = .init(capacitorBridge: bridge)
29
-
29
+
30
30
  NotificationCenter.default.addObserver(
31
31
  self,
32
32
  selector: #selector(appDidBecomeActive),
@@ -40,8 +40,10 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
40
40
  print("App became active. Restarting location monitoring for watch callbacks.")
41
41
  locationCancellable?.cancel()
42
42
  locationCancellable = nil
43
+ timeoutCancellable?.cancel()
44
+ timeoutCancellable = nil
43
45
  locationInitialized = false
44
-
46
+
45
47
  locationService?.stopMonitoringLocation()
46
48
  locationService?.startMonitoringLocation()
47
49
  bindLocationPublisher()
@@ -77,6 +79,8 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
77
79
  locationService?.stopMonitoringLocation()
78
80
  locationCancellable?.cancel()
79
81
  locationCancellable = nil
82
+ timeoutCancellable?.cancel()
83
+ timeoutCancellable = nil
80
84
  locationInitialized = false
81
85
  }
82
86
 
@@ -145,7 +149,7 @@ private extension GeolocationPlugin {
145
149
  locationCancellable = locationService?.currentLocationPublisher
146
150
  .catch { [weak self] error -> AnyPublisher<IONGLOCPositionModel, Never> in
147
151
  print("An error was found while retrieving the location: \(error)")
148
-
152
+
149
153
  if case IONGLOCLocationError.locationUnavailable = error {
150
154
  print("Location unavailable (likely due to backgrounding). Keeping watch callbacks alive.")
151
155
  self?.callbackManager?.sendError(.positionUnavailable)
@@ -160,6 +164,15 @@ private extension GeolocationPlugin {
160
164
  .sink(receiveValue: { [weak self] position in
161
165
  self?.callbackManager?.sendSuccess(with: position)
162
166
  })
167
+
168
+ timeoutCancellable = locationService?.locationTimeoutPublisher
169
+ .sink(receiveValue: { [weak self] error in
170
+ if case .timeout = error {
171
+ self?.callbackManager?.sendError(.timeout)
172
+ } else {
173
+ self?.callbackManager?.sendError(.positionUnavailable)
174
+ }
175
+ })
163
176
  }
164
177
 
165
178
  func requestLocationAuthorisation(type requestType: IONGLOCAuthorisationRequestType) {
@@ -200,10 +213,10 @@ private extension GeolocationPlugin {
200
213
  callbackManager?.sendRequestPermissionsSuccess(Constants.AuthorisationStatus.Status.granted)
201
214
  }
202
215
  if shouldRequestCurrentPosition {
203
- locationService?.requestSingleLocation()
216
+ locationService?.requestSingleLocation(options: IONGLOCRequestOptionsModel(timeout: callbackManager?.timeout))
204
217
  }
205
218
  if shouldRequestLocationMonitoring {
206
- locationService?.startMonitoringLocation()
219
+ locationService?.startMonitoringLocation(options: IONGLOCRequestOptionsModel(timeout: callbackManager?.timeout))
207
220
  }
208
221
  }
209
222
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/geolocation",
3
- "version": "8.0.0-next.3",
3
+ "version": "8.0.0-next.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",
@@ -59,15 +59,15 @@
59
59
  "@semantic-release/changelog": "^6.0.3",
60
60
  "@semantic-release/exec": "^7.1.0",
61
61
  "@semantic-release/git": "^10.0.1",
62
- "@semantic-release/github": "^11.0.1",
63
- "@semantic-release/npm": "^12.0.1",
62
+ "@semantic-release/github": "^12.0.0",
63
+ "@semantic-release/npm": "^13.1.1",
64
64
  "@types/node": "^20.14.8",
65
65
  "eslint": "^8.57.0",
66
66
  "prettier": "^3.3.3",
67
67
  "prettier-plugin-java": "^2.6.4",
68
68
  "rimraf": "^6.0.1",
69
69
  "rollup": "^2.78.1",
70
- "semantic-release": "^24.0.0",
70
+ "semantic-release": "^25.0.1",
71
71
  "swiftlint": "^2.0.0",
72
72
  "typescript": "~5.4.5"
73
73
  },