Installation
Long Ping is a native module (a TurboModule) for React Native 0.76 or newer with the New Architecture. It supports iOS 15.1+ and Android 7.0+ (API 24).
1. Add the package
Section titled “1. Add the package”npm install react-native-long-pingcd ios && pod installThe iOS pod is called LongPing. Rebuild the native app after installing; a JavaScript reload is not
enough.
2. iOS: Info.plist
Section titled “2. iOS: Info.plist”Add the two location usage strings and the location background mode to your app’s Info.plist:
<key>NSLocationWhenInUseUsageDescription</key><string>Your location is shared with dispatch while you are on duty.</string><key>NSLocationAlwaysAndWhenInUseUsageDescription</key><string>Your location is shared with dispatch while you are on duty, including when the app is closed.</string><key>UIBackgroundModes</key><array> <string>location</string></array>| Key | Why |
|---|---|
NSLocationWhenInUseUsageDescription |
Shown in the first (“While Using”) permission prompt. |
NSLocationAlwaysAndWhenInUseUsageDescription |
Shown when the app asks to upgrade to “Always”. |
UIBackgroundModes → location |
Lets location updates continue in the background. |
Write the usage strings for your users. Apple reviews them: say who sees the location and when.
Privacy manifest
Section titled “Privacy manifest”The LongPing pod ships an Apple privacy manifest (PrivacyInfo.xcprivacy). It declares:
- Precise location, collected for app functionality, linked to the user, not used for tracking.
- UserDefaults access, reason
CA92.1(the plugin reads and writes its own settings).
There is nothing to add: Xcode merges it into your app’s privacy report when you archive. Your App Privacy answers in App Store Connect still need to cover location; see App Store & Google Play review.
3. Android: manifest and notification permission
Section titled “3. Android: manifest and notification permission”There is nothing to add to your manifest. The plugin’s manifest brings these permissions with it:
ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, ACCESS_BACKGROUND_LOCATION, FOREGROUND_SERVICE,
FOREGROUND_SERVICE_LOCATION, RECEIVE_BOOT_COMPLETED, WAKE_LOCK, INTERNET, ACCESS_NETWORK_STATE,
plus the foreground service (foregroundServiceType="location") and the boot receiver.
POST_NOTIFICATIONS (Android 13+)
Section titled “POST_NOTIFICATIONS (Android 13+)”Tracking runs in a foreground service, which always has a notification. On Android 13 and newer the
app has to ask for POST_NOTIFICATIONS; without it the service still runs but its notification is
hidden. Long Ping does not ask for it, so request it yourself, for example with React Native’s
PermissionsAndroid:
import { PermissionsAndroid, Platform } from 'react-native';
if (Platform.OS === 'android' && Platform.Version >= 33) { await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);}Set the notification’s text with the notification config.
Optional: REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
Section titled “Optional: REQUEST_IGNORE_BATTERY_OPTIMIZATIONS”LongPing.deviceSettings.requestIgnoreBatteryOptimizations() can open a direct “Allow” prompt to exempt
your app from battery optimization, but only if your app declares this permission. Google Play restricts
it to certain kinds of apps, so the plugin leaves the decision to you. If your Play listing qualifies, add:
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />Without it, the same call opens the system’s battery-optimization list instead. See Android battery managers.
Google Play Services
Section titled “Google Play Services”v0.1 uses the fused location provider only. Devices without Google Play Services get no location.
4. Check it
Section titled “4. Check it”- Build and run the app on a device or simulator.
- Call
LongPing.getState()and log the result. If it resolves, the native module is linked. - Continue with Permissions and the Quick start.