在后台和前台使用 Expo 更改推送通知中的徽章计数

Changing badge count in Push Notifications with Expo in background and foreground

我正在研究将推送通知发送到本机应用程序并阅读 expo 文档的方法,我被两条似乎相互矛盾的信息弄糊涂了。

Notifications will appear in the system notification tray as you've come to expect, and tapping them will open/foreground the app.

(来源:https://docs.expo.io/versions/latest/guides/push-notifications

但在 'why not expo' 部分中指出:

Expo apps don't support background code execution (running code when the app is not foregrounded or the device is sleeping). This means you cannot use background geolocation, play audio in the background, handle push notifications in the background, and more.

(来源:https://docs.expo.io/versions/latest/introduction/why-not-expo

这似乎是矛盾的,因为 'foregrounding' 或 'opening' 一个应用程序暗示它是 运行 在我看来是在后台。

最后我想用这个更改应用程序图标的通知标志,但是鉴于此信息我不清楚这是否可能?在 IOS 和 Android 中?

确实 前台 该应用程序听起来好像该应用程序正在后台主动 运行 宁,因此可以 运行 代码,但正如文档所述,这 目前 仅靠世博会是不可行的。这意味着无法在应用程序处于后台时更改徽章计数。

另一方面,当应用程序在前台或打开通知时,根据this table in the documentation,这变得可行。

可以使用 Notifications.setBadgeNumberAsync(number), whereas for Android the only option available 在 iOS 上设置任意徽章计数是为了使发送的推送通知计入给定频道的徽章计数。