TASIOMIND.DEV — OPERATIONAL▸▸▸FULL STACK DEVELOPER @ GWQ SERVICEPLUS AG▸▸▸FOUNDER — K8SGPT.AI▸▸▸OPEN SOURCE: ACTIVE▸▸▸DISTRIBUTED SYSTEMS / KUBERNETES / AI▸▸▸RUST + GO + PYTHON▸▸▸FIELD TESTED / STATUS — NOMINAL▸▸▸LOCATION: EUROPE/BERLIN▸▸▸TASIOMIND.DEV — OPERATIONAL▸▸▸FULL STACK DEVELOPER @ GWQ SERVICEPLUS AG▸▸▸FOUNDER — K8SGPT.AI▸▸▸OPEN SOURCE: ACTIVE▸▸▸DISTRIBUTED SYSTEMS / KUBERNETES / AI▸▸▸RUST + GO + PYTHON▸▸▸FIELD TESTED / STATUS — NOMINAL▸▸▸LOCATION: EUROPE/BERLIN▸▸▸

Handling permissions in Expo

July 14, 2020

Wichtig: expo-permissions ist deprecated

Frueher gab es expo-permissions. Heute hat jedes Modul eigene Permission APIs.

Beispiele:

  • expo-notifications
  • expo-location
  • expo-camera

Push Notifications (expo-notifications)

code
npx expo install expo-notifications
code
import * as Notifications from "expo-notifications";

const requestNotificationPermission = async () => {
  const { status: existingStatus } = await Notifications.getPermissionsAsync();
  let finalStatus = existingStatus;

  if (existingStatus !== "granted") {
    const { status } = await Notifications.requestPermissionsAsync();
    finalStatus = status;
  }

  return finalStatus === "granted";
};

Location (expo-location)

code
npx expo install expo-location
code
import * as Location from "expo-location";

const requestLocationPermission = async () => {
  const { status } = await Location.requestForegroundPermissionsAsync();
  return status === "granted";
};

Tipps

  • Immer auf status === "granted" pruefen, nicht auf "denied".
  • Bei "denied" Nutzer freundlich in Settings schicken.
  • iOS braucht klare Usage Strings in app.json/app.config.js.

Links