import Constants from 'expo-constants'; import * as Device from 'expo-device'; import * as Notifications from 'expo-notifications'; import { useEffect, useState } from 'react'; import { Button, Platform, Text, View } from 'react-native'; import { requestNotificationPermission } from '../owner/utils'; Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldPlaySound: false, shouldSetBadge: false, shouldShowBanner: true, shouldShowList: true, }), }); export default function AuthNotifications({ setNotificationsEnabled, notificationsEnabled }: { setNotificationsEnabled: (value: boolean) => void, notificationsEnabled: boolean }) { const [expoPushToken, setExpoPushToken] = useState(''); const [channels, setChannels] = useState([]); const [notification, setNotification] = useState( undefined ); useEffect(() => { console.log('notificationsEnabled', notificationsEnabled); registerForPushNotificationsAsync().then(token => { console.log('token', token); token && setExpoPushToken(token) }); if (Platform.OS === 'android') { Notifications.getNotificationChannelsAsync().then(value => setChannels(value ?? [])); } const notificationListener = Notifications.addNotificationReceivedListener(notification => { setNotification(notification); }); const responseListener = Notifications.addNotificationResponseReceivedListener(response => { console.log(response); }); return () => { notificationListener.remove(); responseListener.remove(); }; }, [notificationsEnabled]); return ( Your expo push token: {expoPushToken} {`Channels: ${JSON.stringify( channels.map(c => c.id), null, 2 )}`} Title: {notification && notification.request.content.title} Body: {notification && notification.request.content.body} Data: {notification && JSON.stringify(notification.request.content.data)}