From 62d2d1f7ca41b6aa26d7e749fbef019f2e1f993c Mon Sep 17 00:00:00 2001 From: herrrta <73949927+herrrta@users.noreply.github.com> Date: Wed, 19 Mar 2025 19:17:22 -0400 Subject: [PATCH] fix: generate expo push tokens for real device only --- app/_layout.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/_layout.tsx b/app/_layout.tsx index 7fa4bd9a..f68f0393 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -32,6 +32,7 @@ const BackgroundFetch = !Platform.isTV ? require("expo-background-fetch") : null; import * as FileSystem from "expo-file-system"; +import * as Device from "expo-device"; const Notifications = !Platform.isTV ? require("expo-notifications") : null; import * as ScreenOrientation from "@/packages/expo-screen-orientation"; import { Stack, router, useSegments } from "expo-router"; @@ -331,9 +332,12 @@ function Layout() { await registerBackgroundFetchAsyncSessions(); } - Notifications?.getExpoPushTokenAsync() - .then((token: ExpoPushToken) => token && setExpoPushToken(token)) - .catch((reason: any) => console.log("Failed to get token", reason)); + // only create push token for real devices (pointless for emulators) + if(Device.isDevice) { + Notifications?.getExpoPushTokenAsync() + .then((token: ExpoPushToken) => token && setExpoPushToken(token)) + .catch((reason: any) => console.log("Failed to get token", reason)); + } } useEffect(() => {