/** * Local push notifications for background message delivery. * * Uses a minimal Objective-C native module (ios/LocalNotifications/) that wraps * UNUserNotificationCenter directly. No aps-environment entitlement needed. */ import { AppState, NativeModules } from "react-native"; const { LocalNotifications } = NativeModules; let permissionGranted = false; /** Request notification permissions. Call once at app startup. */ export async function requestNotificationPermissions(): Promise { try { if (!LocalNotifications) return false; permissionGranted = await LocalNotifications.requestPermissions(); } catch { permissionGranted = false; } return permissionGranted; } /** Returns true if the app is currently in the background or inactive. */ export function isAppBackgrounded(): boolean { return AppState.currentState !== "active"; } /** Fire a local notification for an incoming message. */ export async function notifyIncomingMessage( title: string, body: string, ): Promise { if (!permissionGranted || !isAppBackgrounded() || !LocalNotifications) return; try { await LocalNotifications.notify(title, body); } catch { // Best-effort } }