如何从网络向世博会发送通知?

时间:2021-02-10 10:27:57

标签: 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 方法解释的原始方法也不起作用。我根本没有得到回应。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以查看他们的Push Notification Documentation
示例代码

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 }, }); }