@capacitor/geolocation 7.1.5-dev.5 → 7.1.5-dev.6

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 = '14.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(
@@ -1,5 +1,5 @@
1
1
  import Capacitor
2
- //import IONGeolocationLib
2
+ import IONGeolocationLib
3
3
 
4
4
  private enum GeolocationCallbackType {
5
5
  case requestPermissions
@@ -1,5 +1,5 @@
1
1
  import Capacitor
2
- // import IONGeolocationLib
2
+ import IONGeolocationLib
3
3
  import UIKit
4
4
  import Combine
5
5
 
@@ -1,5 +1,5 @@
1
1
  import Capacitor
2
- //import IONGeolocationLib
2
+ import IONGeolocationLib
3
3
 
4
4
  extension IONGLOCPositionModel {
5
5
  func toJSObject() -> JSObject {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/geolocation",
3
- "version": "7.1.5-dev.5",
3
+ "version": "7.1.5-dev.6",
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",
@@ -1,26 +0,0 @@
1
- import CoreLocation
2
-
3
- public enum IONGLOCAuthorisation {
4
- case notDetermined
5
- case restricted
6
- case denied
7
- case authorisedAlways
8
- case authorisedWhenInUse
9
-
10
- init(from status: CLAuthorizationStatus) {
11
- self = switch status {
12
- case .notDetermined: .notDetermined
13
- case .restricted: .restricted
14
- case .denied: .denied
15
- case .authorizedAlways: .authorisedAlways
16
- case .authorizedWhenInUse: .authorisedWhenInUse
17
- @unknown default: .notDetermined
18
- }
19
- }
20
- }
21
-
22
- extension CLLocationManager {
23
- var currentAuthorisationValue: IONGLOCAuthorisation {
24
- .init(from: authorizationStatus)
25
- }
26
- }
@@ -1,16 +0,0 @@
1
- import CoreLocation
2
-
3
- public enum IONGLOCAuthorisationRequestType {
4
- case whenInUse
5
- case always
6
-
7
- func requestAuthorization(using locationManager: CLLocationManager) {
8
- let requestAuthorisation = switch self {
9
- case .whenInUse:
10
- locationManager.requestWhenInUseAuthorization
11
- case .always:
12
- locationManager.requestAlwaysAuthorization
13
- }
14
- requestAuthorisation()
15
- }
16
- }
@@ -1,44 +0,0 @@
1
- import CoreLocation
2
-
3
- public struct IONGLOCPositionModel: Equatable {
4
- private(set) public var altitude: Double
5
- private(set) public var course: Double
6
- private(set) public var horizontalAccuracy: Double
7
- private(set) public var latitude: Double
8
- private(set) public var longitude: Double
9
- private(set) public var speed: Double
10
- private(set) public var timestamp: Double
11
- private(set) public var verticalAccuracy: Double
12
-
13
- private init(altitude: Double, course: Double, horizontalAccuracy: Double, latitude: Double, longitude: Double, speed: Double, timestamp: Double, verticalAccuracy: Double) {
14
- self.altitude = altitude
15
- self.course = course
16
- self.horizontalAccuracy = horizontalAccuracy
17
- self.latitude = latitude
18
- self.longitude = longitude
19
- self.speed = speed
20
- self.timestamp = timestamp
21
- self.verticalAccuracy = verticalAccuracy
22
- }
23
- }
24
-
25
- public extension IONGLOCPositionModel {
26
- static func create(from location: CLLocation) -> IONGLOCPositionModel {
27
- .init(
28
- altitude: location.altitude,
29
- course: location.course,
30
- horizontalAccuracy: location.horizontalAccuracy,
31
- latitude: location.coordinate.latitude,
32
- longitude: location.coordinate.longitude,
33
- speed: location.speed,
34
- timestamp: location.timestamp.millisecondsSinceUnixEpoch,
35
- verticalAccuracy: location.verticalAccuracy
36
- )
37
- }
38
- }
39
-
40
- private extension Date {
41
- var millisecondsSinceUnixEpoch: Double {
42
- timeIntervalSince1970 * 1000
43
- }
44
- }
@@ -1,9 +0,0 @@
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
- }
@@ -1,45 +0,0 @@
1
- import Combine
2
-
3
- public protocol IONGLOCServicesChecker {
4
- func areLocationServicesEnabled() -> Bool
5
- }
6
-
7
- public protocol IONGLOCAuthorisationHandler {
8
- var authorisationStatus: IONGLOCAuthorisation { get }
9
- var authorisationStatusPublisher: Published<IONGLOCAuthorisation>.Publisher { get }
10
-
11
- func requestAuthorisation(withType authorisationType: IONGLOCAuthorisationRequestType)
12
- }
13
-
14
- public enum IONGLOCLocationError: Error {
15
- case locationUnavailable
16
- case timeout
17
- case other(_ error: Error)
18
- }
19
-
20
- public protocol IONGLOCLocationHandler {
21
- var currentLocation: IONGLOCPositionModel? { get }
22
- var currentLocationPublisher: AnyPublisher<IONGLOCPositionModel, IONGLOCLocationError> { get }
23
- var locationTimeoutPublisher: AnyPublisher<IONGLOCLocationError, Never> { get }
24
- func updateConfiguration(_ configuration: IONGLOCConfigurationModel)
25
- }
26
-
27
- public protocol IONGLOCSingleLocationHandler: IONGLOCLocationHandler {
28
- func requestSingleLocation(options: IONGLOCRequestOptionsModel)
29
- }
30
-
31
- public protocol IONGLOCMonitorLocationHandler: IONGLOCLocationHandler {
32
- func startMonitoringLocation(options: IONGLOCRequestOptionsModel)
33
- func startMonitoringLocation()
34
- func stopMonitoringLocation()
35
- }
36
-
37
- public struct IONGLOCConfigurationModel {
38
- private(set) var enableHighAccuracy: Bool
39
- private(set) var minimumUpdateDistanceInMeters: Double?
40
-
41
- public init(enableHighAccuracy: Bool, minimumUpdateDistanceInMeters: Double? = nil) {
42
- self.enableHighAccuracy = enableHighAccuracy
43
- self.minimumUpdateDistanceInMeters = minimumUpdateDistanceInMeters
44
- }
45
- }
@@ -1,152 +0,0 @@
1
- import Combine
2
- import CoreLocation
3
-
4
- public typealias IONGLOCService = IONGLOCServicesChecker & IONGLOCAuthorisationHandler & IONGLOCSingleLocationHandler & IONGLOCMonitorLocationHandler
5
-
6
- public struct IONGLOCServicesValidator: IONGLOCServicesChecker {
7
- public init() {}
8
-
9
- public func areLocationServicesEnabled() -> Bool {
10
- CLLocationManager.locationServicesEnabled()
11
- }
12
- }
13
-
14
- public class IONGLOCManagerWrapper: NSObject, IONGLOCService {
15
- @Published public var authorisationStatus: IONGLOCAuthorisation
16
- public var authorisationStatusPublisher: Published<IONGLOCAuthorisation>.Publisher { $authorisationStatus }
17
-
18
- @Published public var currentLocation: IONGLOCPositionModel?
19
- private var timeoutCancellable: AnyCancellable?
20
- public var currentLocationPublisher: AnyPublisher<IONGLOCPositionModel, IONGLOCLocationError> {
21
- Publishers.Merge($currentLocation, currentLocationForceSubject)
22
- .dropFirst() // ignore the first value as it's the one set on the constructor.
23
- .tryMap { location in
24
- guard let location else { throw IONGLOCLocationError.locationUnavailable }
25
- return location
26
- }
27
- .mapError { $0 as? IONGLOCLocationError ?? .other($0) }
28
- .eraseToAnyPublisher()
29
- }
30
-
31
- public var locationTimeoutPublisher: AnyPublisher<IONGLOCLocationError, Never> {
32
- locationTimeoutSubject.eraseToAnyPublisher()
33
- }
34
-
35
- private let currentLocationForceSubject = PassthroughSubject<IONGLOCPositionModel?, Never>()
36
- private let locationTimeoutSubject = PassthroughSubject<IONGLOCLocationError, Never>()
37
-
38
- private let locationManager: CLLocationManager
39
- private let servicesChecker: IONGLOCServicesChecker
40
-
41
- private var isMonitoringLocation = false
42
-
43
- // Flag used to indicate that the location request has timed out.
44
- // When `true`, the wrapper ignores any location updates received from CLLocationManager.
45
- // This prevents "stale" or "ghost" events from being sent to subscribers after the timeout has occurred.
46
- private var timeoutTriggered = false
47
-
48
- public init(locationManager: CLLocationManager = .init(), servicesChecker: IONGLOCServicesChecker = IONGLOCServicesValidator()) {
49
- self.locationManager = locationManager
50
- self.servicesChecker = servicesChecker
51
- self.authorisationStatus = locationManager.currentAuthorisationValue
52
-
53
- super.init()
54
- locationManager.delegate = self
55
- }
56
-
57
- public func requestAuthorisation(withType authorisationType: IONGLOCAuthorisationRequestType) {
58
- authorisationType.requestAuthorization(using: locationManager)
59
- }
60
-
61
- public func startMonitoringLocation(options: IONGLOCRequestOptionsModel) {
62
- timeoutTriggered = false
63
- isMonitoringLocation = true
64
- locationManager.startUpdatingLocation()
65
- self.startTimer(timeout: options.timeout)
66
- }
67
-
68
- public func startMonitoringLocation() {
69
- guard !timeoutTriggered else {
70
- return
71
- }
72
-
73
- isMonitoringLocation = true
74
- locationManager.startUpdatingLocation()
75
- }
76
-
77
- public func stopMonitoringLocation() {
78
- isMonitoringLocation = false
79
- locationManager.stopUpdatingLocation()
80
- }
81
-
82
- public func requestSingleLocation(options: IONGLOCRequestOptionsModel) {
83
- timeoutTriggered = false
84
- // If monitoring is active meaning the location service is already running
85
- // and calling .requestLocation() will not trigger a new location update,
86
- // we can just return the current location.
87
- if isMonitoringLocation, let location = currentLocation {
88
- currentLocationForceSubject.send(location)
89
- return
90
- }
91
-
92
- self.locationManager.requestLocation()
93
- self.startTimer(timeout: options.timeout)
94
- }
95
-
96
- private func startTimer(timeout: Int) {
97
- timeoutCancellable?.cancel()
98
- timeoutCancellable = nil
99
- timeoutCancellable = Just(())
100
- .delay(for: .milliseconds(timeout), scheduler: DispatchQueue.main)
101
- .sink { [weak self] _ in
102
- guard let self = self else { return }
103
- self.timeoutTriggered = true
104
- self.locationTimeoutSubject.send(.timeout)
105
-
106
- if self.isMonitoringLocation {
107
- self.isMonitoringLocation = false
108
- self.stopMonitoringLocation()
109
- }
110
-
111
- self.timeoutCancellable?.cancel()
112
- self.timeoutCancellable = nil
113
- }
114
- }
115
-
116
- public func updateConfiguration(_ configuration: IONGLOCConfigurationModel) {
117
- locationManager.desiredAccuracy = configuration.enableHighAccuracy ? kCLLocationAccuracyBest : kCLLocationAccuracyThreeKilometers
118
- configuration.minimumUpdateDistanceInMeters.map {
119
- locationManager.distanceFilter = $0
120
- }
121
- }
122
-
123
- public func areLocationServicesEnabled() -> Bool {
124
- servicesChecker.areLocationServicesEnabled()
125
- }
126
- }
127
-
128
- extension IONGLOCManagerWrapper: CLLocationManagerDelegate {
129
- public func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
130
- authorisationStatus = manager.currentAuthorisationValue
131
- }
132
-
133
- public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
134
- guard !timeoutTriggered else {
135
- return
136
- }
137
-
138
- timeoutCancellable?.cancel()
139
- timeoutCancellable = nil
140
- guard let latestLocation = locations.last else {
141
- currentLocation = nil
142
- return
143
- }
144
- currentLocation = IONGLOCPositionModel.create(from: latestLocation)
145
- }
146
-
147
- public func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
148
- timeoutCancellable?.cancel()
149
- timeoutCancellable = nil
150
- currentLocation = nil
151
- }
152
- }