Debugging Guide
This guide covers debugging real-time location events, platform-specific debugging tools, and common patterns for diagnosing issues with @gabriel-sisjr/react-native-background-location.
Android Debugging
Viewing Logs with Logcat
Open a terminal and filter for location-related logs:
# Filter only LocationService logs
adb logcat | grep LocationService
Or to see all relevant logs:
adb logcat | grep -E "(LocationService|BackgroundLocation)"
Testing Steps
- Start the example app
- Grant location permissions (including "Allow all the time")
- Keep Auto-Update Mode enabled (switch should be ON)
- Tap "Start Tracking"
- Observe the logs:
D/LocationService: Setting React context: true
D/LocationService: Starting location tracking for tripId: <ID>
D/LocationService: Received X location(s)
D/LocationService: Handling location: lat=..., lng=..., tripId=...
D/LocationService: Location update event emitted for tripId: <ID>
- In the app, verify that:
- The "Last Location (Live)" section appears and updates
- The "Locations (X)" counter increases automatically
Simulating Location in Android Emulator
To simulate location movement in the Android emulator:
- Open Extended Controls panel (three dots
...on the emulator side) - Go to Location
- Choose an option:
- Single points: Set a specific location
- Routes: Simulate a route (e.g., City bicycle ride)
- GPX/KML file: Import a file with a route
- Click "Play Route" to simulate movement
Expected Logs (Working Correctly)
D/LocationService: Setting React context: true
D/LocationService: Starting location tracking for tripId: abc-123
D/LocationService: Received 1 location(s)
D/LocationService: Handling location: lat=37.422, lng=-122.084, tripId=abc-123
D/LocationService: Location update event emitted for tripId: abc-123
Problem Logs and Solutions
"React context not available"
W/LocationService: React context not available - cannot emit location update event
Solution: Reload the app (Cmd+M or Shake > Reload).
"React instance not active"
W/LocationService: React instance not active - skipping location update event
Solution: Wait a few seconds after opening the app before starting tracking.
"Received 0 location(s)"
D/LocationService: Received 0 location(s)
Problem: GPS/Location in emulator is not configured correctly. See Simulating Location in Android Emulator.
iOS Debugging
Xcode Console
To view native iOS logs for the location module:
- Open the project in Xcode (
example/ios/BackgroundLocationExample.xcworkspace) - Run the app on a simulator or device
- Open the Debug Area console (View > Debug Area > Activate Console)
- Filter logs by searching for
BackgroundLocationorLocationManager
Expected logs when tracking is working:
BackgroundLocation: Starting location updates for tripId: abc-123
BackgroundLocation: CLLocationManager authorized: authorizedAlways
BackgroundLocation: Received location update: lat=37.422, lng=-122.084
BackgroundLocation: Location stored in Core Data, batch count: 5
BackgroundLocation: Event emitted to JS: onLocationUpdate
Simulating Location in iOS Simulator
Using the Simulator Menu
- Run the app on the iOS Simulator
- Go to Features > Location in the Simulator menu
- Choose from:
- None -- No location
- Custom Location... -- Set specific coordinates
- City Bicycle Ride -- Simulates cycling movement
- City Run -- Simulates running movement
- Freeway Drive -- Simulates highway driving
Using GPX Files
For more realistic and repeatable testing, create a .gpx file:
<?xml version="1.0"?>
<gpx version="1.1" creator="Test">
<wpt lat="37.7749" lon="-122.4194">
<time>2026-01-01T00:00:00Z</time>
</wpt>
<wpt lat="37.7750" lon="-122.4195">
<time>2026-01-01T00:00:05Z</time>
</wpt>
</gpx>
Then:
- Add the GPX file to your Xcode project
- Edit your scheme: Product > Scheme > Edit Scheme > Run > Options
- Under Default Location, select your GPX file
Using Xcode Scheme Location
- Product > Scheme > Edit Scheme
- Go to Run > Options
- Check Allow Location Simulation
- Select a Default Location or add a custom GPX file
Debugging Background Location on iOS
Background location on iOS requires special debugging techniques:
- Do NOT attach the Xcode debugger when testing background behavior -- the debugger keeps the app alive artificially
- Instead, use
os_logorNSLogstatements and view them in Console.app (Applications > Utilities > Console) - Filter Console.app by your app's process name
To test true background behavior:
- Start tracking in the app
- Press Home to background the app
- Move around (or use GPX simulation)
- Return to the app and verify locations were collected
- Check Console.app for background location delivery logs
Inspecting Core Data
To inspect the Core Data SQLite database on the iOS Simulator:
-
Find the app's data directory:
# List simulatorsxcrun simctl list devices# Find the app containerxcrun simctl get_app_container <DEVICE_ID> <BUNDLE_ID> data -
Navigate to
Library/Application Support/in the container -
Open the
.sqlitefile with any SQLite browser (e.g., DB Browser for SQLite)
The database contains:
| Table | Contents |
|---|---|
ZLOCATIONENTITY | All stored location points |
ZTRACKINGSTATEENTITY | Current tracking state and options |
Common Problems and Solutions
No Locations Received
Cause: GPS disabled or no simulated location configured.
Solution:
- Android: Configure a location in the emulator's Extended Controls
- iOS: Use Features > Location in the Simulator menu
Locations Received but Not Appearing in App
Cause: React Context is not active or event is not being listened to.
Solution:
- Reload the app
- Verify that "Auto-Update Mode" is enabled in the example app
- Check logs for
Setting React context: true(Android) orEvent emitted to JS(iOS)
Updates Are Slow
Cause: Configuration with updateInterval set too high.
Solution: Use the "High Accuracy" preset which updates every 2 seconds. The example app has 4 presets:
| Preset | Interval | Use Case |
|---|---|---|
| Default | 5s | Balanced |
| High Accuracy | 2s | Best for testing |
| Balanced | 10s | Battery saving |
| Low Power | 30s | Maximum battery saving |
Permission Error
Cause: Location permissions not granted or revoked.
Solution:
- Android: Go to Settings > Apps > BackgroundLocationExample > Permissions > Location > "Allow all the time"
- iOS: Go to Settings > Privacy > Location Services > [Your App] > Always
No Locations on iOS Simulator
Cause: No simulated location configured.
Solution: Use Features > Location in the Simulator menu.
Background Tracking Stops on iOS Device
Cause: Missing Background Mode capability or Info.plist entries.
Solution:
- Verify "Location updates" is checked in Background Modes
- Verify both
NSLocationWhenInUseUsageDescriptionandNSLocationAlwaysAndWhenInUseUsageDescriptionare in Info.plist - Verify the user granted "Always" permission (not just "While Using")
iOS Permission Stuck at "WhenInUse"
Cause: iOS only shows the Always prompt once. If the user dismisses it, they must go to Settings.
Solution: Guide the user to Settings > Privacy > Location Services > [Your App] > Always.
iOS Locations Have Poor Accuracy
Cause: Simulator provides approximated locations.
Solution: Test on a real device for accurate GPS data.
Verification Checklist
To confirm everything is working:
- App compiles without errors
- Permissions were granted
- Logs show React context is set (Android:
React context: true) - Logs show locations are being received
- Logs show events are being emitted to JS
- App shows live location updates
- Location counter increases automatically
Reporting Issues
If the problem persists after following this guide, please provide:
- Complete Logcat logs (Android) or Console.app logs (iOS)
- Screenshots of the app showing the problem
- The tracking configuration you are using
- Whether you are using a physical device, Android emulator, or iOS simulator
- The platform and OS version
- Output of
npx react-native info