react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

Onclick on Notification

Open ErickVoodoo opened this issue 8 years ago • 8 comments

Hello guys, what is the action when user tries to click on arrived notification? How to handle only click on the notification when app is live/foreground? Simple case: Click on notification and redirect user to another page in app. (or open app and do the same thing) Thanks!

ErickVoodoo avatar Apr 16 '18 23:04 ErickVoodoo

+1 Would be so great, it's actually the only thing I need

MartXXIII avatar Jun 19 '18 15:06 MartXXIII

+1

ycman0307 avatar Aug 06 '18 06:08 ycman0307

@zo0r or @Gp2mv3 any ideas if this is possible or something that is planned?

Faolain avatar Jan 10 '19 22:01 Faolain

+1

MBakhtiyor avatar Apr 04 '19 13:04 MBakhtiyor

Hey Guys! the notification has a boolean property called userInteraction, this means the user pressed on the notification.

onNotifictaion(notificication) {
  ....
  if(notification.userInteraction) {
    // Redirect wherever you want  
  }
}

chukitow avatar Apr 17 '19 03:04 chukitow

Anyone get any solution to manage click event and redirect to a particular screen?

urfusion avatar Sep 12 '19 09:09 urfusion

@chukitow unfortunately userInteraction work if a user clicks on Notif in background. For handler on click event on iOS, you can register next handler:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
          didReceiveNotificationResponse:(UNNotificationResponse *)response
          withCompletionHandler:(void (^)(void))completionHandler {
   // The user launched the app.
   if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
     NSMutableDictionary *newUserInfo = [[NSMutableDictionary alloc]initWithDictionary:response.notification.request.content.userInfo];
     [newUserInfo setObject:[NSNumber numberWithBool:TRUE] forKey:@"userInteraction"];
     
     [RNCPushNotificationIOS didReceiveRemoteNotification:newUserInfo];
   }
}

and check this native event in your js event onNotification. For example:

onNotification = (notification) => {
  ...
  if (notification.data.userInteraction) {
    navigate(ROUTE_NAME);
  }
 ...
};

FonDorn avatar Apr 20 '20 10:04 FonDorn

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Apr 21 '21 00:04 github-actions[bot]