Docs menu
React Native
@hospify/org-sdk-react-native works with Expo and bare React Native. Bring the location library you already use.
npx expo install @hospify/org-sdk @hospify/org-sdk-react-native expo-location expo-batteryStart it
import * as Location from "expo-location";
import * as Battery from "expo-battery";
import { Hospify, expoLocation } from "@hospify/org-sdk-react-native";
export const hospify = Hospify.start({
publishableKey: process.env.EXPO_PUBLIC_HOSPIFY_KEY!, // hpk_test_... / hpk_live_...
getToken: () => api.post("/hospify/token").then((r) => r.data.token),
location: expoLocation(Location, async () => Math.round((await Battery.getBatteryLevelAsync()) * 100)),
});The SOS button
useHospifySos gives you the state and actions, and picks up an SOS left open if the app was closed.
TSX
import { Pressable, Text } from "react-native";
import { useHospifySos } from "@hospify/org-sdk-react-native";
import { hospify } from "./hospify";
export function SosButton() {
const { isOpen, state, start, safe, cancel, busy, error } = useHospifySos(hospify);
if (isOpen) {
return (
<>
<Text>{state?.responder ? `${state.responder} is on it` : "Alert sent. Help is being found."}</Text>
<Pressable onPress={() => safe()}><Text>I'm safe</Text></Pressable>
<Pressable onPress={() => cancel()}><Text>It was a mistake</Text></Pressable>
</>
);
}
return (
<Pressable onLongPress={() => start("Need help")} delayLongPress={1500} disabled={busy}>
<Text>Hold for SOS</Text>
{error && <Text>{error.message}</Text>}
</Pressable>
);
}Background location
So location keeps flowing with the screen locked: with Expo, add the expo-location plugin with isIosBackgroundLocationEnabled and isAndroidForegroundServiceEnabled, and ask for background permission when the agent first signs in. In a bare app, add UIBackgroundModes: location on iOS and a location foreground service on Android.
app.json
{
"expo": {
"plugins": [
["expo-location", {
"locationWhenInUsePermission": "Your location is shared with your supervisors only while you have an SOS open.",
"isIosBackgroundLocationEnabled": true,
"isAndroidForegroundServiceEnabled": true
}]
]
}
}