react-native - 如何从网络向 Expo 发送通知?
问题描述
我正在尝试从我的网站向我的应用程序的用户发送通知,但它不起作用。这就是我现在所拥有的:
async function sendPushNotification(expoPushToken, title, description) {
const message = {
to: expoPushToken,
sound: "default",
title: title,
body: description,
badgecount: 1,
};
axios({
method: "post",
url: "https://exp.host/--/api/v2/push/send",
headers: {
Accept: "application/json",
"Accept-encoding": "gzip, deflate",
"Content-Type": "application/json",
},
body: message,
}).then(function (response) {
alert(JSON.stringify(response));
});
}
我试图用 Axios 来做,但没有运气。他们使用该方法解释的原始await fetch
方法也不起作用。我根本没有得到回应。
任何帮助将非常感激。
解决方案
您可以查看他们的推送通知文档
示例代码
async function schedulePushNotification() { await Notifications.scheduleNotificationAsync({ content: { title: "You've got mail! ", body: 'Here is the notification body', data: { data: 'goes here' }, }, trigger: { seconds: 2 }, }); }
推荐阅读
- python - 使用 Raspberry Pi 的远程 GPIO 功能(在 Python 中)时检测连接丢失
- python - 如何在 Python 中使用 selenium 从表中获取数据
- java - 警报管理器在后台不工作
- ada - 如何以及为什么不允许 GNAT.Strings.String_List 使用子句?如何使用 System.Strings.String_List."&" 和中缀表示法?
- django - django + SSL 与本地服务器连接期间的浏览器错误
- amazon-web-services - DynamoDb 扫描返回 get、set 和 Observer?
- c++ - 警告 C26812:枚举类型没有作用域。更喜欢枚举类而不是枚举
- python - Pytorch 几何:张量大小有问题
- html - 媒体查询的宽度有问题,这就是为什么它根本没有响应
- mysql - 使用 JOIN 和 COUNT 查找总计 SQL