android - 在后台和前台使用 Expo 更改推送通知中的角标(Badge)计数

标签 android ios react-native push-notification expo

我正在研究将推送通知发送到 native 应用程序并阅读 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)

但是在“为什么不展览”一节中指出:

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)

这似乎自相矛盾,因为“前景化”或“打开”应用程序意味着它在我看来是在后台运行。

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

最佳答案

确实前台应用程序听起来好像应用程序在后台主动运行,因此可以运行代码,但正如文档所述,这目前不可行单独的世博会。这意味着无法在应用程序处于后台时更改角标(Badge)计数。

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

在 iOS 上设置任意角标(Badge)计数可以用 Notifications.setBadgeNumberAsync(number) 完成,而对于 Android the only option available是使发送的推送通知计入给定 channel 的角标(Badge)计数。

关于android - 在后台和前台使用 Expo 更改推送通知中的角标(Badge)计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52567251/

相关文章:

android - android 1.6 中的设备序列号

ios - UITableViewCell 的背景颜色

android - 向不同的收款人汇款 Paypal

javascript - 在滚动 React Native Animated 上做动画但闪烁

java - 通过 edittext 将项目添加到 ListView

android - 在多个平台上运行一个 Appium 测试

android - YouTube API无法在电视扬声器上播放音乐

ios - 距离计算,acos = Nan 而不是0

node.js - 无法解析依赖关系树,我无法再使用 Node 包管理器安装包

unit-testing - React Native Expo 应用程序 : How to get it to run Jest tests