@capgo/background-geolocation 7.0.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.
@@ -0,0 +1,13 @@
1
+
2
+ Pod::Spec.new do |s|
3
+ s.name = 'CapgoBackgroundGeolocation'
4
+ s.version = '0.0.1'
5
+ s.summary = 'Capacitor plugin which lets you receive geolocation updates even while the app is backgrounded.'
6
+ s.license = 'MIT'
7
+ s.homepage = 'https://github.com/Cap-go/background-geolocation'
8
+ s.author = 'Cap-go'
9
+ s.source = { :git => 'https://github.com/Cap-go/background-geolocation', :tag => s.version.to_s }
10
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
11
+ s.ios.deployment_target = '14.0'
12
+ s.dependency 'Capacitor'
13
+ end
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright 2021 James Diacono
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # Background Geolocation
2
+ <a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
3
+
4
+ <div align="center">
5
+ <h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo</a></h2>
6
+ <h2><a href="https://capgo.app/consulting/?ref=plugin"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
7
+ </div>
8
+
9
+ A Capacitor plugin that lets you receive geolocation updates even while the app is backgrounded. Only iOS and Android platforms are supported.
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ import { BackgroundGeolocation } from "@capgo/background-geolocation";
15
+
16
+ // To start listening for changes in the device's location, add a new watcher.
17
+ // You do this by calling 'addWatcher' with an options object and a callback. A
18
+ // Promise is returned, which resolves to the callback ID used to remove the
19
+ // watcher in the future. The callback will be called every time a new location
20
+ // is available. Watchers can not be paused, only removed. Multiple watchers may
21
+ // exist simultaneously.
22
+ BackgroundGeolocation.addWatcher(
23
+ {
24
+ // If the "backgroundMessage" option is defined, the watcher will
25
+ // provide location updates whether the app is in the background or the
26
+ // foreground. If it is not defined, location updates are only
27
+ // guaranteed in the foreground. This is true on both platforms.
28
+
29
+ // On Android, a notification must be shown to continue receiving
30
+ // location updates in the background. This option specifies the text of
31
+ // that notification.
32
+ backgroundMessage: "Cancel to prevent battery drain.",
33
+
34
+ // The title of the notification mentioned above. Defaults to "Using
35
+ // your location".
36
+ backgroundTitle: "Tracking You.",
37
+
38
+ // Whether permissions should be requested from the user automatically,
39
+ // if they are not already granted. Defaults to "true".
40
+ requestPermissions: true,
41
+
42
+ // If "true", stale locations may be delivered while the device
43
+ // obtains a GPS fix. You are responsible for checking the "time"
44
+ // property. If "false", locations are guaranteed to be up to date.
45
+ // Defaults to "false".
46
+ stale: false,
47
+
48
+ // The minimum number of metres between subsequent locations. Defaults
49
+ // to 0.
50
+ distanceFilter: 50
51
+ },
52
+ function callback(location, error) {
53
+ if (error) {
54
+ if (error.code === "NOT_AUTHORIZED") {
55
+ if (window.confirm(
56
+ "This app needs your location, " +
57
+ "but does not have permission.\n\n" +
58
+ "Open settings now?"
59
+ )) {
60
+ // It can be useful to direct the user to their device's
61
+ // settings when location permissions have been denied. The
62
+ // plugin provides the 'openSettings' method to do exactly
63
+ // this.
64
+ BackgroundGeolocation.openSettings();
65
+ }
66
+ }
67
+ return console.error(error);
68
+ }
69
+
70
+ return console.log(location);
71
+ }
72
+ ).then(function after_the_watcher_has_been_added(watcher_id) {
73
+ // When a watcher is no longer needed, it should be removed by calling
74
+ // 'removeWatcher' with an object containing its ID.
75
+ BackgroundGeolocation.removeWatcher({
76
+ id: watcher_id
77
+ });
78
+ });
79
+
80
+ // The location object.
81
+ {
82
+ // Longitude in degrees.
83
+ longitude: 131.723423719132,
84
+ // Latitude in degrees.
85
+ latitude: -22.40106297456,
86
+ // Radius of horizontal uncertainty in metres, with 68% confidence.
87
+ accuracy: 11,
88
+ // Metres above sea level (or null).
89
+ altitude: 65,
90
+ // Vertical uncertainty in metres, with 68% confidence (or null).
91
+ altitudeAccuracy: 4,
92
+ // Deviation from true north in degrees (or null).
93
+ bearing: 159.60000610351562,
94
+ // True if the location was simulated by software, rather than GPS.
95
+ simulated: false,
96
+ // Speed in metres per second (or null).
97
+ speed: 23.51068878173828,
98
+ // Time the location was produced, in milliseconds since the unix epoch.
99
+ time: 1562731602000
100
+ }
101
+
102
+ // If you just want the current location, try something like this. The longer
103
+ // the timeout, the more accurate the guess will be. I wouldn't go below about
104
+ // 100ms.
105
+ function guess_location(callback, timeout) {
106
+ let last_location;
107
+ BackgroundGeolocation.addWatcher(
108
+ {
109
+ requestPermissions: false,
110
+ stale: true
111
+ },
112
+ function (location) {
113
+ last_location = location || undefined;
114
+ }
115
+ ).then(function (id) {
116
+ setTimeout(function () {
117
+ callback(last_location);
118
+ BackgroundGeolocation.removeWatcher({id});
119
+ }, timeout);
120
+ });
121
+ }
122
+ ```
123
+
124
+ ### Typescript support
125
+
126
+ ```typescript
127
+ import { BackgroundGeolocation } from "@capgo/background-geolocation";
128
+ ```
129
+
130
+ ## Installation
131
+
132
+ This plugin supports Capacitor v7:
133
+
134
+ | Capacitor | Plugin |
135
+ |------------|--------|
136
+ | v7 | v1 |
137
+
138
+ ```sh
139
+ npm install @capgo/background-geolocation
140
+ npx cap update
141
+ ```
142
+
143
+ ### iOS
144
+ Add the following keys to `Info.plist.`:
145
+
146
+ ```xml
147
+ <dict>
148
+ ...
149
+ <key>NSLocationWhenInUseUsageDescription</key>
150
+ <string>We need to track your location</string>
151
+ <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
152
+ <string>We need to track your location while your device is locked.</string>
153
+ <key>UIBackgroundModes</key>
154
+ <array>
155
+ <string>location</string>
156
+ </array>
157
+ ...
158
+ </dict>
159
+ ```
160
+
161
+ ### Android
162
+
163
+ Set the the `android.useLegacyBridge` option to `true` in your Capacitor configuration. This prevents location updates halting after 5 minutes in the background. See https://capacitorjs.com/docs/config and https://github.com/capacitor-community/background-geolocation/issues/89.
164
+
165
+ On Android 13+, the app needs the `POST_NOTIFICATIONS` runtime permission to show the persistent notification informing the user that their location is being used in the background. You may need to [request this permission](https://developer.android.com/develop/ui/views/notifications/notification-permission) from the user, this can be accomplished [using the `@capacitor/local-notifications` plugin](https://capacitorjs.com/docs/apis/local-notifications#checkpermissions).
166
+
167
+ If your app forwards location updates to a server in real time, be aware that after 5 minutes in the background Android will throttle HTTP requests initiated from the WebView. The solution is to use a native HTTP plugin such as [CapacitorHttp](https://capacitorjs.com/docs/apis/http). See https://github.com/capacitor-community/background-geolocation/issues/14.
168
+
169
+ Configration specific to Android can be made in `strings.xml`:
170
+ ```xml
171
+ <resources>
172
+ <!--
173
+ The channel name for the background notification. This will be visible
174
+ when the user presses & holds the notification. It defaults to
175
+ "Background Tracking".
176
+ -->
177
+ <string name="capacitor_background_geolocation_notification_channel_name">
178
+ Background Tracking
179
+ </string>
180
+
181
+ <!--
182
+ The icon to use for the background notification. Note the absence of a
183
+ leading "@". It defaults to "mipmap/ic_launcher", the app's launch icon.
184
+
185
+ If a raster image is used to generate the icon (as opposed to a vector
186
+ image), it must have a transparent background. To make sure your image
187
+ is compatible, select "Notification Icons" as the Icon Type when
188
+ creating the image asset in Android Studio.
189
+
190
+ An incompatible image asset will cause the notification to misbehave in
191
+ a few telling ways, even if the icon appears correctly:
192
+
193
+ - The notification may be dismissable by the user when it should not
194
+ be.
195
+ - Tapping the notification may open the settings, not the app.
196
+ - The notification text may be incorrect.
197
+ -->
198
+ <string name="capacitor_background_geolocation_notification_icon">
199
+ drawable/ic_tracking
200
+ </string>
201
+
202
+ <!--
203
+ The color of the notification as a string parseable by
204
+ android.graphics.Color.parseColor. Optional.
205
+ -->
206
+ <string name="capacitor_background_geolocation_notification_color">
207
+ yellow
208
+ </string>
209
+ </resources>
210
+
211
+ ```
212
+
213
+
214
+ <docgen-index>
215
+
216
+ * [`addWatcher(...)`](#addwatcher)
217
+ * [`removeWatcher(...)`](#removewatcher)
218
+ * [`openSettings()`](#opensettings)
219
+ * [Interfaces](#interfaces)
220
+
221
+ </docgen-index>
@@ -0,0 +1,62 @@
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
+ androidxLocalbroadcastmanagerVersion = project.hasProperty('androidxLocalbroadcastmanagerVersion') ? rootProject.ext.androidxLocalbroadcastmanagerVersion : '1.0.0'
7
+ playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '21.0.1'
8
+ }
9
+
10
+ buildscript {
11
+ repositories {
12
+ google()
13
+ mavenCentral()
14
+ }
15
+ dependencies {
16
+ classpath 'com.android.tools.build:gradle:8.7.3'
17
+ }
18
+ }
19
+
20
+ apply plugin: 'com.android.library'
21
+
22
+ android {
23
+ namespace "com.capgo.capacitor_background_geolocation"
24
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
25
+ defaultConfig {
26
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
27
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
28
+ versionCode 1
29
+ versionName "1.0"
30
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31
+ }
32
+ buildTypes {
33
+ release {
34
+ minifyEnabled false
35
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
36
+ }
37
+ }
38
+ lintOptions {
39
+ abortOnError false
40
+ }
41
+ compileOptions {
42
+ sourceCompatibility JavaVersion.VERSION_21
43
+ targetCompatibility JavaVersion.VERSION_21
44
+ }
45
+ }
46
+
47
+ repositories {
48
+ google()
49
+ mavenCentral()
50
+ }
51
+
52
+
53
+ dependencies {
54
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
55
+ implementation project(':capacitor-android')
56
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
57
+ implementation "androidx.localbroadcastmanager:localbroadcastmanager:$androidxLocalbroadcastmanagerVersion"
58
+ testImplementation "junit:junit:$junitVersion"
59
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
60
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
61
+ implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
62
+ }
@@ -0,0 +1,21 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <application>
3
+ <service
4
+ android:name="com.capgo.capacitor_background_geolocation.BackgroundGeolocationService"
5
+ android:enabled="true"
6
+ android:exported="true"
7
+ android:foregroundServiceType="location" />
8
+ </application>
9
+
10
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
11
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
12
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
13
+ <!-- Android SDK 34+ additionally requires the FOREGROUND_SERVICE_LOCATION
14
+ runtime permission to start a foreground service of type "location". -->
15
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
16
+ <!-- Android SDK 33+ requires the POST_NOTIFICATIONS runtime permission to
17
+ display the foreground service notification. -->
18
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
19
+ <uses-feature android:name="android.hardware.location.gps" />
20
+ </manifest>
21
+