在后台应用程序时使用推送通知更新徽章 [英] Update badge with push notification while app in background

查看:36
本文介绍了在后台应用程序时使用推送通知更新徽章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有推送通知工作,并设法在应用程序被带到前台时更新图标徽章计数.

I have got push notification working and managed to update icon badge count when app is brought to foreground.

我对此有点困惑……iPhone 收到通知并且弹出消息似乎激活了我的应用程序,并且徽章仅在我启动应用程序后更新.

I am a bit confused about this though...the iPhone receives the notification and the pop up message appears to activate my app, and the badge only updates after me starting the app.

这在用户体验方面听起来不太对.我的理解是,徽章计数应该通过增加的计数通知用户需要采取什么行动,但这要到应用程序上线的后期才会发生.

This does not sound right in terms of user experience. My understanding is that the badge count should notify the user of what needs action, through incremented count, but this doe not happen until a later stage when the app is live.

那么有没有办法告诉应用程序在收到推送通知时并在后台更新其徽章计数?

So is there a way to tell the app to update its badge count when it receives push notifications and whilst being in the background?

请注意,我的应用不使用位置信息,并且我在通知注册请求中有 UIRemoteNotificationTypeBadge.

Note that my app does not use location and that I have UIRemoteNotificationTypeBadge in the notification registration request.

干杯自动对焦

推荐答案

由于推送通知是由 iOS 而非您的应用程序处理的,因此您无法在收到推送通知时更改应用程序徽章.

Since push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.

但是你可以在推送通知的payload中发送徽章号,但是你必须在服务器端做计算.

But you can send the badge number in the payload of the push notification, but the you will have to do the calculation server side.

您应该阅读 本地和推送通知编程指南,尤其是通知有效载荷.

You should read Local and Push Notification Programming Guide and especially the The Notification Payload.

有效载荷可能如下所示:

The payload could look like this:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9
    }
}

现在应用程序徽章图标将显示为 9.

Now the app application badge icon will show 9.

这篇关于在后台应用程序时使用推送通知更新徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆