ios icon indicating copy to clipboard operation
ios copied to clipboard

'localNotification' event Handler is not fired

Open aubri61 opened this issue 2 years ago • 6 comments

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).

aubri61 avatar Apr 15 '23 03:04 aubri61

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.

Gjunghoon avatar Apr 22 '23 12:04 Gjunghoon

actually i didn't install (technically removed) notifee and tested it. I don't why the problem occurs.. 🥹

aubri61 avatar May 03 '23 13:05 aubri61

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

alfarodarwaynejay avatar Aug 15 '23 10:08 alfarodarwaynejay

same issue

JuEunSung avatar Sep 15 '23 08:09 JuEunSung

try to touch/tap the localNotification notification, you will get the listener triggered

rakshitbharat avatar Nov 22 '23 14:11 rakshitbharat