react-native-background-geolocation: [SOLVED] Suddenly getting a location unknown error
SOLUTION: The issue was fixed when:
- Updating the app to 4.16.0
- Adding the AppPrivacy manifest file
- Disabling the Location Simulation config in the xcproject by going to Run Config -> Run -> Options -> Uncheck
Allow Location Simulation
Your Environment
- Plugin version: ^4.13.3
- Platform: iOS
- OS version: 17.2
- Device manufacturer / model: Apple Iphone 15 simulator and Apple iPhone 11 Physical Device
- React Native version (
react-native -v): 11.3.3 - Plugin config
{
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 100,
useSignificantChangesOnly: true,
disableElasticity: false,
// Activity Recognition
stopTimeout: 5,
disableMotionActivityUpdates: true,
// Application config
debug: false, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: false, // <-- Auto start tracking when device is powered-up.
url: `${API_URL}/providers/${userSession?.id}/location`,
batchSync: true, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
maxBatchSize: 5,
autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
headers: {
// <-- Optional HTTP headers
Authorization: `Bearer ${userSession?.access_token}`,
}
}
Expected Behavior
We want to be able to use the plugin to automatically send location updates to provided URL We want to be able to manually retrive location data when running BackgroundGeolocation.getCurrentPosition()
Actual Behavior
The plugin is not sending the automatic location updates. Also when using mapbox, the GPS location marker does not appear rendered in the map, as if it were unavailable When running BackgroundGeolocation.getCurrentPosition (after running BackgroundGeolocation.ready()) we get the 0 error that stands for location unknown
Steps to Reproduce
- Run BackgroundGeolocation.ready() on app start
useEffect(() => {
BackgroundGeolocation.ready({
...composeLocationTrackingConfigSignificantOn(userSession), //returns config object
}).then(async state => {
logger.debug('- BackgroundGeolocation state: ', state);
if (!state.enabled) {
const {
backgroundLocationGranted,
fineLocationGranted,
} = await verifyPermissionStatus({ onPermissionsNotGranted() {} });
if (
backgroundLocationGranted &&
fineLocationGranted
) {
BackgroundGeolocation.start(); //run start after plugin is ready
if (ENV === 'DEVELOPMENT') {
Toast.show({
type: 'error',
text1: `Plugin is NOT ready, starting`,
visibilityTime: 1000,
});
}
}
}
if (ENV === 'DEVELOPMENT' && state.enabled) {
Toast.show({
type: 'success',
text1: `Plugin is ready and enabled`,
visibilityTime: 1000,
});
}
});
}, []);
- After, load the map using mapbox, no GPS marker shows up
- At specific times, manually call BackgroundGeolocation.getCurrentPosition()
const {
backgroundLocationGranted,
coarseLocationGranted,
fineLocationGranted,
} = await verifyPermissionStatus({});
if (
backgroundLocationGranted &&
coarseLocationGranted &&
fineLocationGranted
) {
const currentPosition = await BackgroundGeolocation.getCurrentPosition({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
});
const route = `/providers/${providerId}/location`;
const location: [Location] = [{ ...currentPosition }];
await AxiosApiInstance.post(
route,
{ location },
{
headers: {
'X-TUP-Auth-Version': '1',
},
}
);
}
Context
- We were not developing anything related to location tracking at the time the bug presented itself
- The audio capability was removed about 2 months ago as we do not make use of it and it’s flagged as optional in the docs. We did this because Apple would not release our app unless we gave a reason for and made use of it in-app
- I have recently added the App Privacy file that is now required in all new versions of iOS. The contents are below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
PrivacyInfo.xcprivacy
RNTruckupPro
Created by Christian Carneiro on 10/04/24.
Copyright (c) 2024 Truckup LLC. All rights reserved.
-->
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<!-- [1] background_fetch: UserDefaults -->
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
<!-- [2] background_geolocation: UserDefaults -->
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
<string>1C8F.1</string>
</array>
</dict>
<!-- [3] background_geolocation (CocoaLumberjack): FileTimestamp -->
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
<string>0A2A.1</string>
</array>
</dict>
<!-- [4] background_geolocation (CocoaLumberjack): DiskSpace -->
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>E174.1</string>
</array>
</dict>
</array>
</dict>
</plist>
Debug logs
Logs
we do not get any logs, the plugin simply fails to recognize the device's location (both iPhone 15 simulator and physical iPhone 11 device)
About this issue
- Original URL
- State: closed
- Created 3 months ago
- Comments: 35 (15 by maintainers)
is_moving is always false with that configuration.
After running my app with a GPX file on a physical device, I never trust my location. I always reboot my device (after re-launching with app with
[ ] Allow Location Simulationdisabled.The new Privacy Manifest has nothing at all to do with Location Services.
Whatever you’re experiencing is not due to the plugin. I’m testing every day for over 10 years. None of the other thousands of users are reporting anything like this.
I suggest you launch your app in XCode and carefully monitor the logs.
this is not a plugin issue. This an issue with your app or device settings.