chore: add parrainage
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import * as Notifications from "expo-notifications";
|
||||
import * as Device from "expo-device";
|
||||
import { Platform } from "react-native";
|
||||
|
||||
/**
|
||||
* Demande les permissions et retourne le token Expo push.
|
||||
* Retourne null si non supporté (simulateur, refus de permission).
|
||||
*/
|
||||
export async function getExpoPushToken(): Promise<string | null> {
|
||||
if (!Device.isDevice) return null;
|
||||
|
||||
const { status: existing } = await Notifications.getPermissionsAsync();
|
||||
let finalStatus = existing;
|
||||
|
||||
if (existing !== "granted") {
|
||||
const { status } = await Notifications.requestPermissionsAsync();
|
||||
finalStatus = status;
|
||||
}
|
||||
|
||||
if (finalStatus !== "granted") return null;
|
||||
|
||||
if (Platform.OS === "android") {
|
||||
await Notifications.setNotificationChannelAsync("orders", {
|
||||
name: "Nouvelles commandes",
|
||||
importance: Notifications.AndroidImportance.MAX,
|
||||
vibrationPattern: [0, 250, 250, 250],
|
||||
sound: "default",
|
||||
});
|
||||
}
|
||||
|
||||
const tokenData = await Notifications.getExpoPushTokenAsync();
|
||||
return tokenData.data;
|
||||
}
|
||||
Reference in New Issue
Block a user