Hi Guys,
I have a requirement in my project to have remote interactive notifications, Currently the project development is on Expo managed API’s for 6 months now (for the other requirements). Last week I have no luck implementing remote interactive notifications, however I can have it locally. For remote, I can send push notification and receive it on the device but not interactive. According to the documentation for notifications API’s there’s no words states that _category only works locally. so I assumed I can receive interactive push remotely too.
My Attempt was using curl as follow
curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
"to": "ExponentPushToken[XXXXXXXXXXXXXXXX]",
"title":"hello",
"body": "world",
"_category":"alarm",
"data": {"title":"hello", "body":"hello"}
}'
and on the JS i have
Notifications.createCategoryAsync(name="alarm", actions=[
{
"actionId":"Snooze",
"buttonTitle":"Snooze 10 minutes"
}
]);
The device receives the push however it’s not interactive.
I am testing on
-
Android (v7 and v8)
-
expo v32.0.2
-
expo-cli v2.7.0
-
react v16.5.0
-
react-native sdk-31.0.0
Workaround
When the application is on the foreground or background (appears on the multitasking menu). On the notifications listener handler I dismiss the remote notification and generate another local notification
with a categoryId.
Notifications.dismissNotificationAsync(notification.notificationId);
Notifications.presentLocalNotificationAsync({"title":notification.data.title,"body":notification.data.body,"categoryId":"alarm","data":{"title":notification.data.title,"body":notification.data.body}});
It works Good when the app is in the foreground or background but when the Application is completely closed ( not in the multitasking menu ). the App. Notification listener is no longer called when I receive the remote notification but only when I tab the notification. then the workaround doesn’t work and the notification is not longer interactive. When I tab the notification. the app launch and the listener handler is called. but this is too late as I want to have a single interactive notification.
The Question is
-
Can I generate a remote interactive push notification using Expo?
-
Is there a workaround to make it work as expected using local notifications?
-
Should I eject ? search for another react native solution ? is there a module in react native supports interactive remote push notifications to use ?
The Expo project is awesome and saved me a lot of time, My problem is I spent long period building the project functions relying on Expo and React Native, and is too expensive to throw all the work and start over using another framework.
Thanks Guys,