React Native Expo App – Crashing on tap on Push Notification (Only on Android device)

  Kiến thức lập trình

I am building a react native expo app. While implementing push notification functionality using expo-notification, that app is crashing on Android device when I tap on push notification. I am receiving notification properly. However the same App is properly working on iOS device and navigating to desired screen on tapping on notification.

Code from app.json seeking permission-

"android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "permissions": ["android.permission.NOTIFICATIONS"], 
      "useNextNotificationsApi": true
    },

channelID for the all notification type is set as ‘Default’. Even ChapGPT could not solve my problem.

I tried console.log at various points to figure out what’s happening but not getting anything in console. Here is my code for handling tap on notification (as generated by ChatGPT)-

useEffect(() => {
    // This listener will handle notification taps
    const subscription = Notifications.addNotificationResponseReceivedListener(response => {
      const { data } = response.notification.request.content;
      // console.log('Notification data:', data);

      try {
        if (data.type === 'new_message') {
          // Assuming you have a navigation reference set up
          navigationRef.current?.navigate('Chat');
        } else if (data.type === 'new_acceptance') {
          navigationRef.current?.navigate('Chat');
        } else if (data.type === 'new_match') {
          // console.log('Navigating to MessageList');
          navigationRef.current?.navigate('Cut');
        }
      } catch (error) {
        console.log('Error navigating on notification tap:', error);
      }
    });
`your text`
    return () => {
      subscription.remove();
    };
  }, []);

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT