react-native-notifications: Can't get an interactive action response when iOS app is in dead state

Version: react-native-notifications@3.4.2 System: iOS

  • When the app is not dead (foreground, background) and I tap on one of the actions in notification, then registerNotificationOpened callback is called and I get actionResponse there
  • When the app is dead and I tap on notification (not on action), I get notification from Notifications.getInitialNotification()
  • When the app is dead and I tap on one of the actions in push notification, Notifications.getInitialNotification() returns undefined and registerNotificationOpened callback is not called
import { Notifications, NotificationAction, NotificationCategory } from 'react-native-notifications';

Notifications.registerRemoteNotifications();

Notifications.events().registerNotificationOpened((_notification: Notification, completion, actionResponse) => {
    // this callback is called only when app is not dead
    completion();
});

let acceptAction = new NotificationAction('ACCEPT_ACTION', 'foreground', 'Accept', true);
let skipAction = new NotificationAction('SKIP_ACTION', 'foreground', 'Skip', true);
let someCategory = new NotificationCategory('SOME_CATEGORY', [acceptAction, skipAction]);
Notifications.setCategories([someCategory]);

// This will be undefined when the app is dead and I tap on one of the actions in push notification
const notification = await Notifications.getInitialNotification();

Will appreciate any comments. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25

Most upvoted comments

@ninjz Thank you for your advice. But sadly it doesn’t work for me. Neither with Notifications.registerRemoteNotifications(), also not with PushNotificationIOS.requestPermissions(). Seems like I have to dig deeper

EDIT: Nevermind, it worked after a fresh pod install, including the approach by mkizesov. Thank you very much 😃

@mkizesov Thanks for sharing. I’ve gotten to that stage where I’m able to retrieve the notification from the killed state using a similar method.

However, now I’ve been testing these actions on the Apple Watch, and sometimes the phone receives the action, sometimes it doesn’t – usually after the app has been backgrounded for at least 30 minutes. If I go to the phone and respond to the notification action it is properly handled.

Do you think you can give this a try? I’m wondering if it has to do with React Native because I’ve made a sample app using native Swift and am able to consistently get callbacks on the didReceiveNotificationResponse handler no matter how long I’ve left the app for, in killed and background state.

It doesn’t make sense for this to not work on the watch properly, as it would result in unexpected behavior by the users thinking these buttons actually do something…

I’m facing the same issue right now. When pressing an action on the iPhone everything works fine and registerNotificationOpened() gets raised. But when clicking on the action on an AppleWatch “nothing” happens. The app get’s started (background), but the event doesn’t raise.