react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
745 stars 285 forks source link

Cannot access local notification payload after clicking on notification action button #233

Open Joro-Popov opened 3 years ago

Joro-Popov commented 3 years ago

I have followed official documentation and added actionable notification to the IOS app. Buttons are showing and If the app is in foreground or background, when button is pressed, I can handle the notification data and process it. My problem is that when the app is killed and local notification is received, after clicking on action button the app is launched but I cannot see anywhere the data from the notification. No event listener triggered or anything that can lead me to notification's content. I've also debug the native code in XCode and when notification is received and the following code is triggered:

` // Required for localNotification event

But nothing is passed in React-Native code. I've also tried to use getInitialNotification() but it always returns null. How can I access notification from cold start and determine which button is pressed?

I am using

Naturalclar commented 3 years ago

@Joro-Popov Thanks for raising the issue. At the moment I don't think it is possible to get the notification content from cold start with the new notificationRequest. I understand that this is essential part of the notification, and will look into it for the next update.

Joro-Popov commented 3 years ago

Thank you @Naturalclar . I guess we should wait for the next release

Lao-Ben commented 3 years ago

Same problem here (tested only for remote notifications). Is there a workaround to get the data ?

siddharthJadhav commented 3 years ago

I am also facing the same issue.

I am using "react": "16.13.1", "react-native": "0.63.3", "@react-native-community/push-notification-ios": "^1.7.3", "react-native-push-notification": "^6.1.3"

Does anyone have a solution for this?

Joro-Popov commented 3 years ago

I've implemented a workaround for my case which is not the best solution probably but it is working for the purposes of my app. What I've saw is that the notification is processed on the native side and the data is there....the pressed action, title, message and so on. I've parsed the needed data into strings and I've saved it in the async storage. That way, when the JS code starts, I will have the data saved and all I have to do is get it from the storage. This is my implementation:

Screenshot 2020-11-23 at 8 58 23
ForamPattha commented 3 years ago

I've implemented a workaround for my case which is not the best solution probably but it is working for the purposes of my app. What I've saw is that the notification is processed on the native side and the data is there....the pressed action, title, message and so on. I've parsed the needed data into strings and I've saved it in the async storage. That way, when the JS code starts, I will have the data saved and all I have to do is get it from the storage. This is my implementation:

Screenshot 2020-11-23 at 8 58 23

@Joro-Popov can you please share your code here or steps to implement code for actionable notification

ninjz commented 3 years ago

@Joro-Popov When you click on the notification action while the app is terminated, do you launch the app to the foreground or to the background? I'm having issues getting this to work when launching it into the background to do some processing. Thanks

randomtoni commented 3 years ago

@Joro-Popov are you using PushNotificationIOS.addNotificationRequest or just PushNotification.localNotification? (I'm supposing you're also using react-native-push-notification)