wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

EXC_BREAKPOINT error on IOS for no reason #886

Closed rbayuokt closed 2 years ago

rbayuokt commented 2 years ago

hi, I have an error on IOS side, I don't know why it's always like this, I've following the docs, this error I get when I try to send a push notification on foreground, thank you if someone wants to help me

image
mjmostachetti commented 2 years ago

I have also experienced this issue and I fixed it by wrapping the calling code in a useEffect hook.

nates-dennis commented 2 years ago

I have also experienced this issue and I fixed it by wrapping the calling code in a useEffect hook.

do you have a code example of this fix

mjmostachetti commented 2 years ago

Put the notification subscriptions within a useEffect hook. This is part of react. https://reactjs.org/docs/hooks-effect.html

nates-dennis commented 2 years ago

so as an example (using the documentation)

import { Notifications } from 'react-native-notifications';
import React, { useEffect } from 'react';
const App = () => {
    Notifications.registerRemoteNotifications();

    useEffect(() => {
        Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
                    // TODO: Send the token to my server so it could send back push notifications...
                    console.log("Device Token Received", event.deviceToken);
            });
        Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
                console.error(event);
            });

        Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
            console.log("Notification Received - Foreground", notification.payload);

            // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
            completion({alert: true, sound: true, badge: false});
                });

        Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void, action: NotificationActionResponse) => {
                console.log("Notification opened by device user", notification.payload);
                console.log(`Notification opened with an action identifier: ${action.identifier} and response text: ${action.text}`);
                completion();
            });

        Notifications.events().registerNotificationReceivedBackground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
                console.log("Notification Received - Background", notification.payload);

                // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
                completion({alert: true, sound: true, badge: false});
            });
    });

 return null;
}
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] commented 2 years ago

The issue has been closed for inactivity.