wix / react-native-notifications

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

IOS background and foreground notification is not working #1003

Open aman-8149 opened 1 year ago

aman-8149 commented 1 year ago

The below code is working fine before I had started configuring the foreground notification for iOS. After foreground configuration, it stopped working. This is my AppDelegate.m file. The configuration for device token is working fine. I’m able to generate device token and I had also configured the foreground and background notification according to the documentation but it’s not working.

import "AppDelegate.h"

import "RNNotifications.h"

import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

Below is my function in my React Native project where I had written a code for device token and background notification when app is closed. Device token code works fine but the background code is not working for iOS.

const configurePushNotifications = useCallback(async () => { Notifications.registerRemoteNotifications(); Notifications.events().registerRemoteNotificationsRegistered(event => { console.log('event.deviceToken', event.deviceToken); storeTokenID(event.deviceToken); }); Notifications.events().registerNotificationReceivedBackground( (notification, completion) => { completion(NotificationBackgroundFetchResult.NO_DATA); }, ); }, [storeTokenID]);

Below is my code for foreground notification for iOS-

useEffect(() => { Notifications.events().registerNotificationReceivedForeground( (notification, completion) => { console.log('notify=>', notification.payload.aps); Notifications.postLocalNotification( { identifier: notification.identifier, body: notification.payload.aps?.alert, title: ‘my notification’, sound: 'chime.aiff', badge: 1, type: 'test type’, thread: '', payload: ‘hello world’, }, parseInt(notification.payload.from, 10), ); completion({ alert: notification.payload, sound: true, badge: true, }); }, ); }, []); I’m using APNS to push the notification for IOS for testing. I have also configured the push notifications in my developer account as documented.

Please advise why push notifications are not working for me for iOS for both background and foreground. As stated above, it was working for background earlier, but that is also stopped working after I tried to configuring for foreground for iOS.