Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add code snippet and update a link #448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion docs/sdk/react-native.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,27 @@ Radar.trackOnce().then((result) => {
- **`ERROR_SERVER`**: internal server error
- **`ERROR_UNKNOWN`**: unknown error

To track the user location each time the app is foreground, use this code snippet:

```javascript
useEffect(() => {
// Define a function to handle the app state change
const handleAppStateChange = (nextAppState) => {
if (nextAppState === 'active') {
Radar.trackOnce();
}
};

// Add the AppState listener
const subscription = AppState.addEventListener('change', handleAppStateChange);

// Remove the AppState listener when the component unmounts
return () => {
subscription.remove();
};
}, []);
```

Learn about platform-specific implementations of this function in the [iOS SDK documentation](/sdk/ios) and [Android SDK documentation](/sdk/android).

### Background tracking
Expand Down Expand Up @@ -322,7 +343,7 @@ Radar.off('error');

Because React Native loads and parses your JavaScript bundle on each app launch, and because background tracking may launch the app in the background, background tracking with the React Native module can increase battery usage.

On iOS, the app loads and parses the JavaScript bundle when the app is launched. If you do not want to receive events in JavaScript and you want to disable this in the background, check `launchOptions` for the `UIApplicationLaunchOptionsLocationKey` to conditionally parse and load the JavaScript bundle. Learn more about this key [here](https://developer.apple.com/uikit/uiapplicationlaunchoptionslocationkey).
On iOS, the app loads and parses the JavaScript bundle when the app is launched. If you do not want to receive events in JavaScript and you want to disable this in the background, check `launchOptions` for the `UIApplicationLaunchOptionsLocationKey` to conditionally parse and load the JavaScript bundle. Learn more about this key [here](https://developer.apple.com/documentation/uikit/uiapplicationlaunchoptionslocationkey).

On Android, a receiver in the React Native module loads and parses the JavaScript bundle when the app is launched in the background. If you do not want to receive events in JavaScript and you want to disable this, add an override to your manifest:

Expand Down
Loading