简体   繁体   English

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

[英]Changing badge count in Push Notifications with Expo in background and foreground

I was looking into ways to send push notifications to a native app and reading the expo documentation, I got confused by two bits of information that seem to contradict each other.我正在研究将推送通知发送到本机应用程序并阅读 expo 文档的方法,我被两条似乎相互矛盾的信息弄糊涂了。

Notifications will appear in the system notification tray as you've come to expect, and tapping them will open / foreground the app.通知将如您所料出现在系统通知托盘中,点击它们将打开/前台应用程序。

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

But in the section 'why not expo' it states:但在“为什么不世博会”一节中,它指出:

Expo apps don't support background code execution (running code when the app is not foregrounded or the device is sleeping). Expo 应用程序不支持后台代码执行(当应用程序未在前台运行或设备处于休眠状态时运行代码)。 This means you cannot use background geolocation, play audio in the background, handle push notifications in the background , and more.这意味着您不能使用后台地理定位、在后台播放音频、在后台处理推送通知等。

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

That seems contradictory since 'foregrounding' or 'opening' an app implies that it was running in the background how I see it.这似乎是矛盾的,因为“前景化”或“打开”应用程序意味着它在我看来是在后台运行的。

In the end I would like to change the notification badge of an app icon with this, but given this info it's not clear to me if this is possible?最后我想用这个更改应用程序图标的通知徽章,但鉴于此信息,我不清楚这是否可能? In IOS and Android?在IOS和Android?

Indeed foregrounding the app sounds as if the app was actively running in the background and could therefore run code, but as the documentation states, this is not currently feasible with Expo alone.实际上,将应用程序置于前台听起来好像应用程序在后台积极运行,因此可以运行代码,但正如文档所述,目前仅使用 Expo 是不可行的。 This entails that changing the badge count while the app is in background cannot be done.这意味着无法在应用程序处于后台时更改徽章计数。

On the other hand, when the app is in foreground or the notification is being open, this becomes feasible according to this table in the documentation .另一方面,当应用程序处于前台或通知正在打开时,根据文档中的此表,这变得可行。

Setting an arbitrary badge count on iOS can be done with Notifications.setBadgeNumberAsync(number) , whereas for Android the only option available is to make the sent push notifications count towards the badge count for a given channel.可以使用Notifications.setBadgeNumberAsync(number)在 iOS 上设置任意徽章计数,而对于 Android ,唯一可用的选项是使发送的推送通知计入给定频道的徽章计数。

remove notification badge count for android - Notifications.dismissAllNotificationsAsync()删除 android 的通知徽章计数 - Notifications.dismissAllNotificationsAsync()

expo dismissAllNotificationAsync expo dismissAllNotificationAsync

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用程序处于后台时显示推送通知的徽章计数 - Show the badge count for push notifications when the app is in background Firebase 推送通知与 cordova 前景和背景 n - Firebase push notifications with cordova foreground and background n 当应用程序在后台(Titanium)时,Android 5上的推送通知未送达 - 但它确实在前台 - Push notifications on Android 5 not delivered when app in background (Titanium) - But it does in foreground Android-通过GCM在前台/后台使用应用发送推送通知 - Android - Sending Push Notifications via GCM with app in foreground/background 如何在后台在Android应用程序图标上计算推送通知消息徽章 - How to count Push notification message badge on android app icon in background 减少推送徽章数 - Decrement the push badge count Detached Expo (ExpoKit) 推送通知 - Detached Expo (ExpoKit) Push Notifications 当 foreground_show 设置为 false 并且我的应用程序在后台时,如何获取推送通知以显示? - How do I get push notifications to show when foreground_show is set to false and my app is in the background? Xamarin 中的后台推送通知 - Background push notifications in Xamarin 当App位于前台时,FCM推送通知将被替换 - FCM Push Notifications are replacing when App is in Foreground
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM