简体   繁体   English

iOS6中的自动递增推送通知徽章

[英]Auto Increment Push Notification Badge in iOS6

I am getting the Push Notification from the Server. 我从服务器获得推送通知。 The server always sends badge=1 in payload. 服务器始终在有效负载中发送badge = 1。

The server side developer doesn't know anything about it. 服务器端开发人员对此一无所知。 Can anybody tell me how can the server side developer handle badge count values so that iOS app will get the updated badge count (auto incremented badge count)? 任何人都可以告诉我服务器端开发人员如何处理徽章计数值,以便iOS应用程序获得更新的徽章计数(自动递增徽章计数)?

  1. Can I auto increment it on iOS app side? 我可以在iOS应用程序端自动增加它吗? If so, how? 如果是这样,怎么样?

  2. If no then how can the server developer handle badge count on server ? 如果不是那么服务器开发人员如何处理服务器上的徽章计数? I saw several links which tell me that the server side should handle badge count. 我看到几个链接告诉我服务器端应该处理徽章计数。

Any sample or reference would be helpful. 任何样本或参考都会有所帮助。

I think you can't do it iOS app side. 我认为你不能在iOS应用程序方面做到这一点。 It must come from the server. 它必须来自服务器。

What I do: 我所做的:

  • the server store an app badge number in the db for each user. 服务器在每个用户的数据库中存储应用程序徽章编号。
  • when the server send a notification, it increase that number by 1. 当服务器发送通知时,它会将该数字增加1。
  • you also need to create a web service to reset the badge number which you will call when you launch the application. 您还需要创建一个Web服务来重置您在启动应用程序时调用的徽章编号。

You can change the badge number in the app with that line (eg in applicationDidBecomeActive): 您可以使用该行更改应用程序中的徽章编号(例如,在applicationDidBecomeActive中):

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    application.applicationIconBadgeNumber = 0;
}

Hope this help. 希望这有帮助。

The badge count is one of the parameters that can be sent in an Apple Push Notification payload from the server. 徽章计数是可以从服务器的Apple推送通知有效负载中发送的参数之一。 The badge count usually reflects an amount of some kind of new data (such as unread emails) that the server knows about and wants to alert the app user about it. 徽章计数通常反映服务器知道的某些新数据(例如未读电子邮件)的数量,并且想要向应用程序用户发出警告。 Therefore it should be done in the server side. 因此,它应该在服务器端完成。 The code that currently always sends 1 in the badge count should be changed to select the correct count. 应更改当前始终在徽章计数中发送1的代码以选择正确的计数。

You can do it in the client (increment it by one whenever a push notification arrives), but that won't be a good idea, because push notifications are not guaranteed to arrive. 您可以在客户端中执行此操作(每当推送通知到达时将其递增一次),但这不是一个好主意,因为无法保证推送通知到达。 In addition, it will only be possible if the notification contains an alert in addition to the badge number, and the user taps on the notification to open the app (otherwise, your app wouldn't get the notification data if it's not already running). 此外,只有通知除了徽章编号之外还包含警报,并且用户点击通知以打开应用程序(否则,如果通知数据尚未运行,您的应用程序将无法获取通知数据) 。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM