【发布时间】:2020-12-28 19:45:59
【问题描述】:
TL;DR 如何通过 Expo 的 Push API 发送交互式通知
请提供以下信息:
SDK 版本:40
平台(Android/iOS/web/all):全部
使用以下代码,我创建了一个类别并使用getNotificationCategoriesAsync,确认了它的存在。
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);
在 API 方面,我使用了下面的请求并将@username/appName 替换为上面记录的内容(experienceId)。我已经在 ios 和 android 的真实设备和模拟器上尝试过这个,即使通知确实发送了,它也缺少交互方面。
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",
}'
我还尝试将“_category”替换为“categoryId”或“categoryIdentifier”或“category”。这些都没有奏效。有没有人能够成功地做到这一点!如果有怎么办!提前致谢
【问题讨论】:
标签: react-native push-notification expo