Closed rbayuokt closed 2 years ago
I have also experienced this issue and I fixed it by wrapping the calling code in a useEffect hook.
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
Put the notification subscriptions within a useEffect hook. This is part of react. https://reactjs.org/docs/hooks-effect.html
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;
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
The issue has been closed for inactivity.
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