@nitra/geolocation 7.1.6 → 8.2.0

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.
@@ -9,10 +9,10 @@ Pod::Spec.new do |s|
9
9
  s.license = package['license']
10
10
  s.homepage = package['repository']['url']
11
11
  s.author = package['author']
12
- s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
12
+ s.source = { :git => package['repository']['url'], :tag => "v#{s.version}" }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '14.0'
14
+ s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'IONGeolocationLib', spec='~> 1.0'
16
+ s.dependency 'IONGeolocationLib', '>= 2.1.0'
17
17
  s.swift_version = '5.1'
18
18
  end
package/Package.swift CHANGED
@@ -2,28 +2,24 @@
2
2
  import PackageDescription
3
3
 
4
4
  let package = Package(
5
- name: "GeolocationCapacitor",
6
- platforms: [.iOS(.v13)],
5
+ name: "CapacitorGeolocation",
6
+ platforms: [.iOS(.v15)],
7
7
  products: [
8
8
  .library(
9
- name: "GeolocationCapacitor",
9
+ name: "CapacitorGeolocation",
10
10
  targets: ["GeolocationPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
14
+ .package(url: "https://github.com/ionic-team/ion-ios-geolocation.git", from: "2.1.0")
14
15
  ],
15
16
  targets: [
16
- .binaryTarget(
17
- name: "IONGeolocationLib",
18
- url: "https://github.com/ionic-team/ion-ios-geolocation/releases/download/1.0.0/IONGeolocationLib.zip",
19
- checksum: "b117d3681a947f5d367e79abdb3bfc9abf7ab070ea5279d7da634ddd2d54ffdb" // sha-256
20
- ),
21
17
  .target(
22
18
  name: "GeolocationPlugin",
23
19
  dependencies: [
24
20
  .product(name: "Capacitor", package: "capacitor-swift-pm"),
25
21
  .product(name: "Cordova", package: "capacitor-swift-pm"),
26
- "IONGeolocationLib"
22
+ .product(name: "IONGeolocationLib", package: "ion-ios-geolocation")
27
23
  ],
28
24
  path: "ios/Sources/GeolocationPlugin"),
29
25
  .testTarget(
package/README.md CHANGED
@@ -16,6 +16,17 @@ 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
+ :::info[Background Location Usage Strings]
20
+
21
+ This Capacitor plugin does not support background geolocation directly. However, it relies on
22
+ [`ion-ios-geolocation`](https://github.com/ionic-team/ion-ios-geolocation), which can report
23
+ location in the background. As a result, Apple requires you to include a
24
+ `NSLocationAlwaysAndWhenInUseUsageDescription` entry in your `Info.plist`. Since this permission
25
+ prompt won’t appear to users, you can safely use the same description string as for
26
+ `NSLocationWhenInUseUsageDescription`.
27
+
28
+ :::info
29
+
19
30
  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
31
 
21
32
  ## Android
@@ -31,9 +42,85 @@ This plugin requires the following permissions be added to your `AndroidManifest
31
42
 
32
43
  The first two permissions ask for location data, both fine and coarse, and the last line is optional but necessary if your app _requires_ GPS to function. You may leave it out, though keep in mind that this may mean your app is installed on devices lacking GPS hardware.
33
44
 
45
+ :::note
46
+
47
+ If you only require approximate location (variable accuracy but usually around 2 kilometers), you may just declare `ACCESS_COARSE_LOCATION` and `<uses-feature`, and use `enableHighAccuracy=false` when requesting location
48
+
49
+ :::note
50
+
34
51
  Read about [Setting Permissions](https://capacitorjs.com/docs/android/configuration#setting-permissions) in the [Android Guide](https://capacitorjs.com/docs/android) for more information on setting Android permissions.
35
52
 
36
53
 
54
+ ## Running the Example App
55
+
56
+ The `example-app` directory contains a Capacitor app for testing the plugin locally. It references the plugin via `file:../`, so any changes you build are immediately reflected.
57
+
58
+ ### 1. Build the plugin
59
+
60
+ From the repo root:
61
+
62
+ ```bash
63
+ npm install
64
+ npm run build
65
+ ```
66
+
67
+ ### 2. Install example app dependencies
68
+
69
+ ```bash
70
+ cd example-app
71
+ npm install
72
+ npm run build
73
+ ```
74
+
75
+ ### 3. Android
76
+
77
+ ```bash
78
+ npx cap sync android
79
+ npx cap run android
80
+ ```
81
+
82
+ Or open in Android Studio:
83
+
84
+ ```bash
85
+ npx cap open android
86
+ ```
87
+
88
+ ### 4. iOS
89
+
90
+ The iOS plugin depends on [`ion-ios-geolocation`](https://github.com/nitra/ion-ios-geolocation). Clone it as `ios-lib` inside the repo root:
91
+
92
+ ```bash
93
+ git clone https://github.com/nitra/ion-ios-geolocation ios-lib
94
+ ```
95
+
96
+ Since `IONGeolocationLib` is not yet published to the public CocoaPods registry, uncomment the local pod path in `example-app/ios/App/Podfile` for local development:
97
+
98
+ ```ruby
99
+ pod 'IONGeolocationLib', :path => '../../../ios-lib'
100
+ ```
101
+
102
+ > **Note:** `ios-lib` is not committed — clone it manually. Do not commit the uncommented line.
103
+
104
+ Sync and open in Xcode:
105
+
106
+ ```bash
107
+ npx cap sync ios
108
+ npx cap open ios
109
+ ```
110
+
111
+ In Xcode, select your **Team** under **Signing & Capabilities** for the `App` target, then run on a device or simulator.
112
+
113
+ ### After plugin changes
114
+
115
+ Every time you modify the plugin source, rebuild and re-sync before running:
116
+
117
+ ```bash
118
+ # from repo root:
119
+ npm run build
120
+ # from example-app:
121
+ npx cap sync android # or ios
122
+ ```
123
+
37
124
  ## API
38
125
 
39
126
  <docgen-index>
@@ -151,20 +238,22 @@ Not available on web.
151
238
 
152
239
  #### Position
153
240
 
154
- | Prop | Type | Description | Since |
155
- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ----- |
156
- | **`timestamp`** | <code>number</code> | Creation timestamp for coords | 1.0.0 |
157
- | **`coords`** | <code>{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number \| null; altitude: number \| null; speed: number \| null; heading: number \| null; }</code> | The GPS coordinates along with the accuracy of the data | 1.0.0 |
241
+ | Prop | Type | Description | Since |
242
+ | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
243
+ | **`timestamp`** | <code>number \| null</code> | GNSS satellite timestamp for coords, in milliseconds since the Unix epoch. On Android, this is populated only when a GNSS RMC NMEA message is available. On iOS and web, this is always `null`. | 1.0.0 |
244
+ | **`coords`** | <code>{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number \| null; altitude: number \| null; speed: number \| null; heading: number \| null; magneticHeading: number \| null; trueHeading: number \| null; headingAccuracy: number \| null; course: number \| null; isMock?: boolean; provider?: string; }</code> | The GPS coordinates along with the accuracy of the data | 1.0.0 |
158
245
 
159
246
 
160
247
  #### PositionOptions
161
248
 
162
- | Prop | Type | Description | Default | Since |
163
- | --------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
164
- | **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
165
- | **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 7.1.0 of the plugin, it is also used to determine the interval of location updates for `watchPosition`. | <code>10000</code> | 1.0.0 |
166
- | **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
167
- | **`minimumUpdateInterval`** | <code>number</code> | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |
249
+ | Prop | Type | Description | Default | Since |
250
+ | ---------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | ----- |
251
+ | **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
252
+ | **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. | <code>10000</code> | 1.0.0 |
253
+ | **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
254
+ | **`minimumUpdateInterval`** | <code>number</code> | The minimum update interval for `watchPosition`. Not to be confused with `interval`. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |
255
+ | **`interval`** | <code>number</code> | Desired interval in milliseconds to receive location updates in `watchPosition`. For very low values of `interval` (a couple seconds or less), the platform may not guarantee timely location updates - they may take longer than specified. The platform may also be able to provide location updates faster than `interval`. You may use `minimumUpdateInterval` to control that behavior. For backwards compatibility with version 7.1.x, if no value is passed, the default value of this parameter is that of `timeout`. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>`timeout`</code> | 8.0.0 |
256
+ | **`enableLocationFallback`** | <code>boolean</code> | Whether to fall back to the Android framework's `LocationManager` in case Google Play Service's location settings checks fail. This can happen for multiple reasons - e.g. device has no Play Services or device has no network connection (Airplane Mode) If set to `false`, failures are propagated to the caller. Note that `LocationManager` may not be as effective as Google Play Services implementation. If the device's in airplane mode, only the GPS provider is used, which may take longer to return a location, depending on GPS signal. This means that to receive location in such circumstances, you may need to provide a higher timeout. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>true</code> | 8.0.0 |
168
257
 
169
258
 
170
259
  #### ClearWatchOptions
@@ -229,10 +318,12 @@ The following table list all the plugin errors:
229
318
  | OS-PLUG-GLOC-0007 | Android, iOS | Location services are not enabled. |
230
319
  | OS-PLUG-GLOC-0008 | iOS | Application's use of location services was restricted. |
231
320
  | OS-PLUG-GLOC-0009 | Android | Request to enable location was denied. |
232
- | OS-PLUG-GLOC-0010 | Android | Could not obtain location in time. Try with a higher timeout. |
321
+ | OS-PLUG-GLOC-0010 | Android, iOS | Could not obtain location in time. Try with a higher timeout. |
233
322
  | OS-PLUG-GLOC-0011 | Android | Timeout needs to be a positive value. |
234
323
  | OS-PLUG-GLOC-0012 | Android | WatchId not found. |
235
324
  | OS-PLUG-GLOC-0013 | Android | WatchId needs to be provided. |
236
325
  | OS-PLUG-GLOC-0014 | Android | Google Play Services error user resolvable. |
237
326
  | OS-PLUG-GLOC-0015 | Android | Google Play Services error. |
238
327
  | OS-PLUG-GLOC-0016 | Android | Location settings error. |
328
+ | OS-PLUG-GLOC-0017 | Android | Unable to retrieve location because device has both Network and Location turned off. |
329
+ | OS-PLUG-GLOC-0018 | Android | Location permissions are not declared in manifest. Make sure at least ACCESS_COARSE_LOCATION is declared in AndroidManifest.xml, and optionally ACCESS_FINE_LOCATION if you require precise location access. |
@@ -1,32 +1,54 @@
1
- ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
- playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '21.3.0'
7
- }
8
-
9
1
  buildscript {
10
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.24'
2
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '2.2.20'
11
3
  repositories {
12
4
  google()
13
5
  mavenCentral()
6
+ maven {
7
+ url = "https://plugins.gradle.org/m2/"
8
+ }
14
9
  }
15
10
  dependencies {
16
- classpath 'com.android.tools.build:gradle:8.7.1'
11
+ classpath 'com.android.tools.build:gradle:8.13.0'
17
12
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13
+ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
14
+ classpath 'io.github.gradle-nexus:publish-plugin:1.3.0'
15
+ }
18
16
  }
19
17
  }
20
18
 
21
19
  apply plugin: 'com.android.library'
22
- apply plugin: 'kotlin-android'
20
+
21
+ // AGP 9 (used by host apps such as the example app) bundles Kotlin and already
22
+ // registers the `kotlin` extension when the Android plugin is applied. Older AGP
23
+ // (8.13, used for the standalone Maven publish build) does not, so apply the
24
+ // Kotlin plugin only when it is missing — applying it twice fails with
25
+ // "extension with name 'kotlin' already registered".
26
+ if (project.extensions.findByName('kotlin') == null) {
27
+ apply plugin: 'kotlin-android'
28
+ }
29
+
30
+ ext {
31
+ capacitorVersion = System.getenv('CAPACITOR_VERSION')
32
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
33
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
34
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
35
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
36
+ playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '21.3.0'
37
+ kotlinxCoroutinesVersion = project.hasProperty('kotlinxCoroutinesVersion') ? rootProject.ext.kotlinxCoroutinesVersion : '1.10.2'
38
+ }
39
+
40
+ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
41
+ apply plugin: 'io.github.gradle-nexus.publish-plugin'
42
+ apply from: file('../scripts/android/publish-root.gradle')
43
+ apply from: file('../scripts/android/publish-module.gradle')
44
+ }
23
45
 
24
46
  android {
25
- namespace "com.capacitorjs.plugins.geolocation"
26
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
47
+ namespace = "com.capacitorjs.plugins.geolocation"
48
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
27
49
  defaultConfig {
28
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
29
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
50
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 28
51
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
30
52
  versionCode 1
31
53
  versionName "1.0"
32
54
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -34,16 +56,19 @@ android {
34
56
  buildTypes {
35
57
  release {
36
58
  minifyEnabled false
37
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
59
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
38
60
  }
39
61
  }
40
62
  lintOptions {
41
- abortOnError false
63
+ abortOnError = false
42
64
  }
43
65
  compileOptions {
44
66
  sourceCompatibility JavaVersion.VERSION_21
45
67
  targetCompatibility JavaVersion.VERSION_21
46
68
  }
69
+ publishing {
70
+ singleVariant("release")
71
+ }
47
72
  }
48
73
 
49
74
  kotlin {
@@ -59,13 +84,17 @@ repositories {
59
84
 
60
85
  dependencies {
61
86
  implementation fileTree(dir: 'libs', include: ['*.jar'])
62
- implementation 'com.github.nitra:ion-android-geolocation:fake-SNAPSHOT'
63
-
64
- implementation project(':capacitor-android')
87
+ implementation 'com.github.nitra:ion-android-geolocation:fake-SNAPSHOT'
88
+
89
+ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
90
+ implementation "com.capacitorjs:core:$capacitorVersion"
91
+ } else {
92
+ implementation project(':capacitor-android')
93
+ }
65
94
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
66
95
 
67
- implementation 'com.google.code.gson:gson:2.10.1'
68
- implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4")
96
+ implementation 'com.google.code.gson:gson:2.13.2'
97
+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$kotlinxCoroutinesVersion")
69
98
  implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
70
99
 
71
100
  testImplementation "junit:junit:$junitVersion"
@@ -68,4 +68,14 @@ object GeolocationErrors {
68
68
  code = formatErrorCode(16),
69
69
  message = "Location settings error."
70
70
  )
71
+
72
+ val NETWORK_LOCATION_DISABLED_ERROR = ErrorInfo(
73
+ code = formatErrorCode(17),
74
+ message = "Unable to retrieve location because device has both Network and Location turned off."
75
+ )
76
+
77
+ val LOCATION_MANIFEST_PERMISSIONS_MISSING = ErrorInfo(
78
+ code = formatErrorCode(18),
79
+ message = "Location permissions are not declared in manifest. Make sure at least ACCESS_COARSE_LOCATION is declared in AndroidManifest.xml, and optionally ACCESS_FINE_LOCATION if you require precise location access."
80
+ )
71
81
  }