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
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
self.moduleName = @"ibc_upgrade";
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};
[RNNotifications startMonitorNotifications];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
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.
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.
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
if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
endif
} @end
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.