iPhone:自动增加徽章计数器 [英] iPhone: Increment badge counter automatically
问题描述
可能的重复:
推送通知徽章自动增加.
我已经为我的 iPhone 应用程序实现了推送通知.每当我收到消息时,我都希望将徽章值加一,这样我就不需要在推送通知负载中传递它.可能吗?
I have implemented Push Notification for my iPhone application. Whenever I get the message, I want to increment badge value by one so I need not to pass it in Push Notification payload. Is it possible?
从这里我了解到我必须从服务器端管理它,所以那是唯一的方法吗?我必须将先前的值存储在数据库中并在发送下一条消息时获取最后一个值?苹果不是自动支持这个,就像每当收到推送通知时增加 application.applicationIconBadgeNumber 一样.
From here I learnt that I have to manage that from server side, so that's the only way? I had to store the previous value in Database and get the last value whenever I send next message? Isn't Apple support this automatically like incrementing application.applicationIconBadgeNumber whenever Push Notification received.
服务器端管理徽章号的问题是如果用户已经看到之前的推送通知消息,你会发送错误的徽章号!
The problem with managing Badge number from server side is if user has already seen the previous Push Notification message, you would send wrong badge number!
推荐答案
这不是真正的问题.客户端只需要让服务器知道它看到了什么消息.其他人都在做,所以只需学习如何做,然后去做.
It's not really a problem. The client just needs to let the server know what messages it has seen. Everyone else is doing it, so just learn how to do it and do it.
您可以使用以下方法设置徽章计数器:
You can set the badge counter using:
[UIApplication sharedApplication].applicationIconBadgeNumber = badgeCount;
每次执行时,都应将badgeCount
发送到服务器,以便服务器知道当前计数.
Every time you do, you should send badgeCount
to the server, so that the server knows the current count.
这篇关于iPhone:自动增加徽章计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!