Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'localNotification' event Handler is not fired #403

Open
aubri61 opened this issue Apr 15, 2023 · 6 comments
Open

'localNotification' event Handler is not fired #403

aubri61 opened this issue Apr 15, 2023 · 6 comments

Comments

@aubri61
Copy link

aubri61 commented Apr 15, 2023

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

@Gjunghoon
Copy link

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.

@aubri61
Copy link
Author

aubri61 commented May 3, 2023

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

@alfarodarwaynejay
Copy link

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

@JuEunSung
Copy link

same issue

@rakshitbharat
Copy link

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

@Qurat-ul-ainn
Copy link

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

Do u find any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants