npx expo install react-native-background-geolocation
npx expo install react-native-background-fetch
npx expo install expo-gradle-ext-vars
- Add the following three
plugins
:
{
"expo": {
"name": "your-app-name",
"plugins": [
+ [
+ "react-native-background-geolocation", {
+ "license": "YOUR_LICENSE_KEY_HERE"
+ }
+ ],
+ [
+ "expo-gradle-ext-vars", {
+ "googlePlayServicesLocationVersion": "21.1.0",
+ "appCompatVersion": "1.4.2"
+ }
+ ],
+ "react-native-background-fetch"
]
}
}
If you've purchased an HMS Background Geolocation License for installing the plugin on Huawei devices without Google Play Services installed, add your HMS Background Geolocation license key:
{
"expo": {
"name": "your-app-name",
"plugins": [
[
"react-native-background-geolocation", {
"license": "YOUR_LICENSE_KEY_HERE",
+ "hmsLicense": "YOUR_HMS_LICENSE_HERE"
}
]
]
}
}
react-native-background-geolocation >= 3.11.0
.
- Add the following Usage Descriptions to the
ios.infoPlist
section: - These strings are used by the OS when requesting permission from the user. It's up to you to re-write these strings as-desired.
{
"expo": {
"name": "your-app-name",
.
.
.
"ios": {
+ "infoPlist": {
+ "NSLocationAlwaysAndWhenInUseUsageDescription": "[CHANGEME] This app requires location in the background",
+ "NSLocationWhenInUseUsageDescription": "[CHANGEME] This app requires location while in use",
+ "NSMotionUsageDescription": "[CHANGEME] This app uses motion-detection to determine the motion-activity of the device (walking, vehicle, bicycle, etc)"
+ }
}
}
}
- If you configure the plugin with
locationAuthorizationRequest: 'WhenInUse'
, you can omitNSLocationAlwaysAndWhenInUseUsageDescription
- If you configure the plugin with
disableMotionActivityUpdates: true
, you can omitNSMotionUsageDescription
- Add the following
UIBackgroundModes
to theios.infoPlist
section:
{
"expo": {
"name": "your-app-name",
.
.
.
"ios": {
"infoPlist": {
"NSLocationAlwaysAndWhenInUseUsageDescription": "[CHANGEME] This app requires location in the background",
"NSLocationWhenInUseUsageDescription": "[CHANGEME] This app requires location while in use",
"NSMotionUsageDescription": "[CHANGEME] This app uses motion-detection to determine the motion-activity of the device (walking, vehicle, bicycle, etc)",
+ "UIBackgroundModes": [
+ "location",
+ "fetch",
+ "processing"
+ ],
+ "BGTaskSchedulerPermittedIdentifiers": [
+ "com.transistorsoft.fetch",
+ "com.transistorsoft.customtask"
+ ]
}
}
}
}
- While field-testing the plugin configured with
debug: true
(to enable debug found FX), you can optionally add theUIBackgroundMode
audio
so you can hear debug sounds while your app is in the background:
{
"expo": {
"name": "your-app-name",
.
.
.
"ios": {
"infoPlist": {
"NSLocationAlwaysAndWhenInUseUsageDescription": "[CHANGEME] This app requires location in the background",
"NSLocationWhenInUseUsageDescription": "[CHANGEME] This app requires location while in use",
"NSMotionUsageDescription": "[CHANGEME] This app uses motion-detection to determine the motion-activity of the device (walking, vehicle, bicycle, etc)",
"UIBackgroundModes": [
"location",
"fetch",
"processing",
+ "audio"
]
}
}
}
}
You must rebuild your Android app for the added plugins to be evaluated.
- If you're developing locally:
npx expo prebuild
- If you're using Expo EAS, you must first run
eas build
. - Adjust
--profile
as desired. - You must build ALL platforms, both iOS and Android:
eas build --profile development