TL;DR How do I send interactive notifications through Expo’s Push API
Please provide the following:
SDK Version: 40
Platforms(Android/iOS/web/all): All
Using the following code and I have created a category and using getNotificationCategoriesAsync
, confirmed its existence.
import Constants from "expo-constants";
import * as Notifications from "expo-notifications";
// Set up Category
Notifications.setNotificationCategoryAsync("basic", [
{ identifier: "Yes", buttonTitle: "Yes 😀" },
{ identifier: "No", buttonTitle: "No 😕" },
])
// Check category is there
Notifications.getNotificationCategoriesAsync().then((categories) => {
console.log(categories)});
// Get experienceId
experienceId = Constants.manifest.id;
console.log(experienceId);
On the API side, I have used the request below and replaced @username/appName with what was logged above (experienceId). I have tried this with real devices and simulators for both ios and android and even though the notification does send, it is missing the interactive aspect.
curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
"to": "ExponentPushToken[XXXXXXXXXXXXXXXX]",
"title":"hello",
"body": "world",
"_category":"@username/appName:basic",
}'
I have also tried replacing “_category” with “categoryId” or “categoryIdentifier” or “category”. None of which has worked. Has anyone been able to successfully do this! If so how! Thanks in advance
You were really close, the experienceId and category are joined with a hyphen "-". Looking at the source code on iOS you can see the format string:
curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
"to": "ExponentPushToken[XXXXXXXXXXXXXXXX]",
"title":"hello",
"body": "world",
"_category":"@username/appName-basic",
}'