'localNotification' event Handler is not fired
I add local noti request in my app and the notification is delivered well but the event listener is not called.
PushNotificationIOS.addNotificationRequest({
id: 'asdfdf',
title: 'dasdf',
isCritical: true,
isSilent: true,
body: '일어나야지~~',
fireDate: date,
});
this is my code to send notification
useEffect(() => {
console.log('uef');
PushNotificationIOS.addEventListener('localNotification', () => {
console.log('로컬 노티 왔어요~~');
});
return () => {
PushNotificationIOS.removeEventListener('localNotification');
};
}, []);
this is how i wrote on App.tsx useeffect just to test if the handler is triggered.
I don't know if the trouble happens because of 'react-native-splash-screen'? i saw a issue mentioning this library..
My AppDelegate.h
#import <UserNotifications/UNUserNotificationCenter.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
My AppDelegate.mm
#import "AppDelegate.h"
// firebase
#import <Firebase.h>
#import <UserNotifications/UserNotifications.h>
#import <RNCPushNotificationIOS.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"
#import <React/RCTAppSetupUtils.h>
....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
return YES;
}
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}
// Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
Please help me figure out the problem ... how can others are using this feature with no problem? did I write something wrong in my appdelegate? :(
I want to do some work when the notification is delivered to users(not clicked).
Hi, we're facing same issue. and we found out that after installing notifee, it failed to fire 'localNotification'. after removing notifee, it works fine. so it might be helpful if you've used notifee so far.
actually i didn't install (technically removed) notifee and tested it. I don't why the problem occurs.. 🥹
any update on this issue? I am facing the same problem.
- react-native 0.62.2
- @react-native-community/push-notification-ios 1.8.0
same issue
try to touch/tap the localNotification notification, you will get the listener triggered