Expo通知在.apk构建上延迟太多。

huangapple go评论52阅读模式
英文:

Expo notifications arriving with too much delay on .apk build

问题

我正在开发我的Expo应用,使用Expo通知功能。目前,我正在处理Android版本的通知。我已经设置了Firebase Cloud Messaging凭据,但是当我制作.apk文件时,通知会有很大的延迟,我希望它们能准确无误地送达。我在文档中阅读到了以下内容:

来自 https://docs.expo.dev/versions/latest/sdk/notifications/#permissions

文档中提到了要在manifest.xml文件中添加一个字符串,但是我在我的项目中找不到这个文件。

你知道该怎么做吗?我希望我的通知能在0 - 2秒内到达,而当前的通知需要20秒才能到达。

英文:

I am developing my expo app which uses expo notifications. For now, I am working on the notifications for the android version. I set up the Firebase Cloud Messaging credentials, but, when I make the .apk file, the notifications arrive with a huge delay, and I want them to be precise. I read this in the docs:
From https://docs.expo.dev/versions/latest/sdk/notifications/#permissions
Which talks about a string to add in manifest.xml file, however I do not have this file in my project.

Do you know what to do? I want my notifications to arrive with 0 - 2 s delay, while the current ones arrive after 20s.

答案1

得分: 1

如果您正在使用Expo进行React Native项目开发,您不需要自己创建或修改AndroidManifest.xml文件,因为Expo在构建过程中会自动生成它。相反,您可以使用app.json文件配置您的通知。

为了确保您的通知能够尽快到达,您可以尝试以下操作:

在您的app.json文件中将expo.android.enableBackgroundNotification设置为true,以启用后台通知功能,即使应用不在前台也能接收通知。

将通知的优先级属性设置为high,以确保尽快传送通知。您可以在通知负载的数据字段中使用priority属性来实现这一点。

以下是如何在app.json文件中配置通知的示例:

{
  "expo": {
    ...
    "android": {
      "useNextNotificationsApi": true,
      "enableBackgroundNotification": true,
      "priority": "max"
    },
    ...
  }
}

另外,请确保您的服务器端代码及时发送通知并具有正确的优先级。还需要注意,网络连接和其他因素可能会影响通知的传递时间,因此您可能无法始终达到0-2秒的延迟。

英文:

If you are using Expo for your React Native project, you don't need to create or modify the AndroidManifest.xml file yourself, as it's automatically generated by Expo during the build process. Instead, you can configure your notifications using the app.json file.

To ensure that your notifications arrive with minimal delay, you can try the following:

Enable background notifications by setting expo.android.enableBackgroundNotification to true in your app.json file. This will allow your app to receive notifications even when it's not in the foreground.

Set the priority property of your notification to high to ensure that it gets delivered as quickly as possible. You can do this using the priority property in the data field of your notification payload.

Here's an example of how you can configure your notifications in the app.json file:

{
  "expo": {
    ...
    "android": {
      "useNextNotificationsApi": true,
      "enableBackgroundNotification": true,
      "priority": "max"
    },
    ...
  }
}

Additionally, make sure that your server-side code is sending the notifications promptly and with the correct priority. It's also worth noting that network connectivity and other factors can affect the delivery time of notifications, so you may not always be able to achieve a 0-2 second delay.

huangapple
  • 本文由 发表于 2023年5月10日 21:10:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218844.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定