react-native - 远程交互式推送通知 - 如何?
问题描述
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”。这些都没有奏效。有没有人能够成功地做到这一点!如果有怎么办!提前致谢
解决方案
你真的很亲密,experienceId 和 category 用连字符“-”连接起来。查看 iOS 上的源代码可以看到格式字符串:
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",
}'
推荐阅读
- android - 如何通过 okhttp 验证 Http/2?
- react-native - React 导航将初始路由传递给 createappContainer
- python - Pygame 的类实现
- python - 将 2D 矩阵的“切片”按元素相乘以形成 3D 矩阵
- redux - 接受减速器的函数的流类型不匹配
- java - 如何理解我的 Java 循环的哪一部分输出星号?
- c# - C# WPF - Material Design 文本框的问题
- java - 无法在 freemarker 模板上获取弹簧标签
- firebase - 通过 Firebase 的 Arkit 2 ARWorldMap 持久性
- java - 无法获取 Arduino 传感器数据