@capacitor/geolocation 7.1.5-dev.1 → 7.1.5-dev.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,8 +1,6 @@
1
1
  import Capacitor
2
-
3
2
  // import IONGeolocationLib
4
3
  import UIKit
5
-
6
4
  import Combine
7
5
 
8
6
  @objc(GeolocationPlugin)
@@ -0,0 +1,9 @@
1
+ import Foundation
2
+
3
+ public struct IONGLOCRequestOptionsModel {
4
+ let timeout: Int
5
+
6
+ public init(timeout: Int? = nil) {
7
+ self.timeout = timeout ?? 5000
8
+ }
9
+ }
@@ -13,7 +13,6 @@ public protocol IONGLOCAuthorisationHandler {
13
13
 
14
14
  public enum IONGLOCLocationError: Error {
15
15
  case locationUnavailable
16
- //TODO changes here
17
16
  case timeout
18
17
  case other(_ error: Error)
19
18
  }
@@ -26,13 +25,11 @@ public protocol IONGLOCLocationHandler {
26
25
  }
27
26
 
28
27
  public protocol IONGLOCSingleLocationHandler: IONGLOCLocationHandler {
29
- //TODO changes here
30
- func requestSingleLocation(timeout: Int?)
28
+ func requestSingleLocation(options: IONGLOCRequestOptionsModel)
31
29
  }
32
30
 
33
31
  public protocol IONGLOCMonitorLocationHandler: IONGLOCLocationHandler {
34
- //TODO changes here
35
- func startMonitoringLocation(timeout: Int?)
32
+ func startMonitoringLocation(options: IONGLOCRequestOptionsModel)
36
33
  func startMonitoringLocation()
37
34
  func stopMonitoringLocation()
38
35
  }
@@ -14,10 +14,9 @@ public struct IONGLOCServicesValidator: IONGLOCServicesChecker {
14
14
  public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
15
15
  @Published public var authorisationStatus: IONGLOCAuthorisation
16
16
  public var authorisationStatusPublisher: Published<IONGLOCAuthorisation>.Publisher { $authorisationStatus }
17
-
17
+
18
18
  @Published public var currentLocation: IONGLOCPositionModel?
19
19
  private var timeoutCancellable: AnyCancellable?
20
-
21
20
  public var currentLocationPublisher: AnyPublisher<IONGLOCPositionModel, IONGLOCLocationError> {
22
21
  Publishers.Merge($currentLocation, currentLocationForceSubject)
23
22
  .dropFirst() // ignore the first value as it's the one set on the constructor.
@@ -40,47 +39,37 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
40
39
  private let servicesChecker: IONGLOCServicesChecker
41
40
 
42
41
  private var isMonitoringLocation = false
43
- private var shouldRunTimeout = false
44
-
42
+
45
43
  public init(locationManager: CLLocationManager = .init(), servicesChecker: IONGLOCServicesChecker = IONGLOCServicesValidator()) {
46
44
  self.locationManager = locationManager
47
45
  self.servicesChecker = servicesChecker
48
46
  self.authorisationStatus = locationManager.currentAuthorisationValue
49
-
47
+
50
48
  super.init()
51
49
  locationManager.delegate = self
52
50
  }
53
-
51
+
54
52
  public func requestAuthorisation(withType authorisationType: IONGLOCAuthorisationRequestType) {
55
53
  authorisationType.requestAuthorization(using: locationManager)
56
54
  }
57
- //TODO changes here
58
- public func startMonitoringLocation(timeout: Int? = nil) {
59
- let timeoutValue = timeout ?? 5000
55
+
56
+ public func startMonitoringLocation(options: IONGLOCRequestOptionsModel) {
60
57
  isMonitoringLocation = true
61
-
62
- print("======================> startMonitoringLocation timeout: ", timeoutValue)
63
- self.startTimer(timeout: timeoutValue)
58
+ self.startTimer(timeout: options.timeout)
64
59
  locationManager.startUpdatingLocation()
65
60
  }
66
61
 
67
62
  public func startMonitoringLocation() {
68
63
  isMonitoringLocation = true
69
64
  locationManager.startUpdatingLocation()
70
- print("======================> startMonitoringLocation sem timer ")
71
65
  }
72
-
66
+
73
67
  public func stopMonitoringLocation() {
74
68
  isMonitoringLocation = false
75
69
  locationManager.stopUpdatingLocation()
76
70
  }
77
71
 
78
- //TODO changes here
79
- public func requestSingleLocation(timeout: Int? = nil) {
80
- // Fallback to default timeout (5000) when the parameter is nil,
81
- // since optional defaults in Swift don't apply when nil is explicitly passed.
82
- let timeoutValue = timeout ?? 5000
83
-
72
+ public func requestSingleLocation(options: IONGLOCRequestOptionsModel) {
84
73
  // If monitoring is active meaning the location service is already running
85
74
  // and calling .requestLocation() will not trigger a new location update,
86
75
  // we can just return the current location.
@@ -88,10 +77,8 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
88
77
  currentLocationForceSubject.send(location)
89
78
  return
90
79
  }
91
-
92
- self.startTimer(timeout: timeoutValue)
80
+ self.startTimer(timeout: options.timeout)
93
81
  self.locationManager.requestLocation()
94
- print("======================> requestLocation")
95
82
  }
96
83
 
97
84
  private func startTimer(timeout: Int) {
@@ -101,9 +88,7 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
101
88
  .delay(for: .milliseconds(timeout), scheduler: DispatchQueue.main)
102
89
  .sink { [weak self] _ in
103
90
  guard let self = self else { return }
104
- print("======================> Native lib: timeout triggered (\(timeout)ms)")
105
91
  self.locationTimeoutSubject.send(.timeout)
106
- print("======================> timeoutCancellable 4")
107
92
  self.timeoutCancellable?.cancel()
108
93
  self.timeoutCancellable = nil
109
94
  }
@@ -115,7 +100,7 @@ public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
115
100
  locationManager.distanceFilter = $0
116
101
  }
117
102
  }
118
-
103
+
119
104
  public func areLocationServicesEnabled() -> Bool {
120
105
  servicesChecker.areLocationServicesEnabled()
121
106
  }
@@ -125,25 +110,18 @@ extension IONGLOCManagerWrapper: CLLocationManagerDelegate {
125
110
  public func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
126
111
  authorisationStatus = manager.currentAuthorisationValue
127
112
  }
128
-
113
+
129
114
  public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
130
115
  timeoutCancellable?.cancel()
131
116
  timeoutCancellable = nil
132
- print("======================> timeoutCancellable 2")
133
-
134
117
  guard let latestLocation = locations.last else {
135
-
136
- print("======================> currentLocation 1")
137
118
  currentLocation = nil
138
119
  return
139
120
  }
140
-
141
- print("======================> currentLocation 2")
142
121
  currentLocation = IONGLOCPositionModel.create(from: latestLocation)
143
122
  }
144
-
123
+
145
124
  public func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
146
- print("======================> timeoutCancellable 3")
147
125
  timeoutCancellable?.cancel()
148
126
  timeoutCancellable = nil
149
127
  currentLocation = nil
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/geolocation",
3
- "version": "7.1.5-dev.1",
3
+ "version": "7.1.5-dev.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",