I'm facing an issue with my Ionic/Capacitor app regarding background location tracking on both iOS and Android platforms.
Problem:
I'm trying to implement background location tracking for my Ionic app on both iOS and Android devices. For Android, I have included the following permissions in my AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
android:description="@string/location_permission_message"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
android:permissionGroup="android.permission-group.LOCATION"
android:protectionLevel="dangerous"
android:description="@string/location_permission_message"
/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
And for iOS, I've added the necessary description keys in my Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your location is required to provide XYZ feature.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your location is required to provide XYZ feature.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your location is required to provide XYZ feature.</string>
Approach Tried:
I attempted to utilize Firebase to send push notifications and trigger background location updates. Upon receiving a notification, I'm invoking BackgroundGeolocation.addWatcher() to start tracking the location in the background. Once the location is obtained, I call BackgroundGeolocation.removeWatcher() to stop tracking.
Issue Encountered:
Unfortunately, despite implementing this flow, I'm encountering issues with consistent background location tracking on both platforms. The background location updates seem unreliable, and sometimes they don't occur at all.