@capacitor/geolocation 7.1.2 → 7.1.4
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/Package.swift
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import PackageDescription
|
|
3
3
|
|
|
4
4
|
let package = Package(
|
|
5
|
-
name: "
|
|
6
|
-
platforms: [.iOS(.
|
|
5
|
+
name: "CapacitorGeolocation",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
7
|
products: [
|
|
8
8
|
.library(
|
|
9
|
-
name: "
|
|
9
|
+
name: "CapacitorGeolocation",
|
|
10
10
|
targets: ["GeolocationPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
package/README.md
CHANGED
|
@@ -16,6 +16,14 @@ Apple requires privacy descriptions to be specified in `Info.plist` for location
|
|
|
16
16
|
- `NSLocationAlwaysAndWhenInUseUsageDescription` (`Privacy - Location Always and When In Use Usage Description`)
|
|
17
17
|
- `NSLocationWhenInUseUsageDescription` (`Privacy - Location When In Use Usage Description`)
|
|
18
18
|
|
|
19
|
+
> [!NOTE]
|
|
20
|
+
> This Capacitor plugin does not support background geolocation directly. However, it relies on
|
|
21
|
+
> [`ion-ios-geolocation`](https://github.com/ionic-team/ion-ios-geolocation), which can report
|
|
22
|
+
> location in the background. As a result, Apple requires you to include a
|
|
23
|
+
> `NSLocationAlwaysAndWhenInUseUsageDescription` entry in your `Info.plist`. Since this permission
|
|
24
|
+
> prompt won’t appear to users, you can safely use the same description string as for
|
|
25
|
+
> `NSLocationWhenInUseUsageDescription`.
|
|
26
|
+
|
|
19
27
|
Read about [Configuring `Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist) in the [iOS Guide](https://capacitorjs.com/docs/ios) for more information on setting iOS permissions in Xcode
|
|
20
28
|
|
|
21
29
|
## Android
|
package/android/build.gradle
CHANGED
|
@@ -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.
|
|
10
|
+
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.25'
|
|
11
11
|
repositories {
|
|
12
12
|
google()
|
|
13
13
|
mavenCentral()
|
|
14
14
|
}
|
|
15
15
|
dependencies {
|
|
16
|
-
classpath 'com.android.tools.build:gradle:8.7.
|
|
16
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
17
17
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Capacitor
|
|
2
2
|
import IONGeolocationLib
|
|
3
|
+
import UIKit
|
|
3
4
|
|
|
4
5
|
import Combine
|
|
5
6
|
|
|
@@ -17,6 +18,7 @@ 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
23
|
private var statusInitialized = false
|
|
22
24
|
private var locationInitialized: Bool = false
|
|
@@ -24,6 +26,30 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
24
26
|
override public func load() {
|
|
25
27
|
self.locationService = IONGLOCManagerWrapper()
|
|
26
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)
|
|
27
53
|
}
|
|
28
54
|
|
|
29
55
|
@objc func getCurrentPosition(_ call: CAPPluginCall) {
|
|
@@ -49,6 +75,9 @@ public class GeolocationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
49
75
|
|
|
50
76
|
if (callbackManager?.watchCallbacks.isEmpty) ?? false {
|
|
51
77
|
locationService?.stopMonitoringLocation()
|
|
78
|
+
locationCancellable?.cancel()
|
|
79
|
+
locationCancellable = nil
|
|
80
|
+
locationInitialized = false
|
|
52
81
|
}
|
|
53
82
|
|
|
54
83
|
callbackManager?.sendSuccess(call)
|
|
@@ -113,18 +142,24 @@ private extension GeolocationPlugin {
|
|
|
113
142
|
func bindLocationPublisher() {
|
|
114
143
|
guard !locationInitialized else { return }
|
|
115
144
|
locationInitialized = true
|
|
116
|
-
locationService?.currentLocationPublisher
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
print("
|
|
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.")
|
|
122
151
|
self?.callbackManager?.sendError(.positionUnavailable)
|
|
152
|
+
return Empty<IONGLOCPositionModel, Never>()
|
|
153
|
+
.eraseToAnyPublisher()
|
|
154
|
+
} else {
|
|
155
|
+
self?.callbackManager?.sendError(.positionUnavailable)
|
|
156
|
+
return Empty<IONGLOCPositionModel, Never>()
|
|
157
|
+
.eraseToAnyPublisher()
|
|
123
158
|
}
|
|
124
|
-
}
|
|
159
|
+
}
|
|
160
|
+
.sink(receiveValue: { [weak self] position in
|
|
125
161
|
self?.callbackManager?.sendSuccess(with: position)
|
|
126
162
|
})
|
|
127
|
-
.store(in: &cancellables)
|
|
128
163
|
}
|
|
129
164
|
|
|
130
165
|
func requestLocationAuthorisation(type requestType: IONGLOCAuthorisationRequestType) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/geolocation",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.4",
|
|
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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
-
"verify:ios": "xcodebuild -scheme
|
|
34
|
+
"verify:ios": "xcodebuild -scheme CapacitorGeolocation -destination generic/platform=iOS",
|
|
35
35
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
36
|
"verify:web": "npm run build",
|
|
37
37
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
@@ -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",
|