3

Possible Duplicate:
Push-Notification Badge auto increment.

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?

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!

Community
  • 1
  • 1
Paresh Masani
  • 7,474
  • 12
  • 73
  • 139
  • 1
    How is this question any different from the one you linked to? ([Push-Notification Badge auto increment.](http://stackoverflow.com/questions/1942605/push-notification-badge-auto-increment)) – Stephen Darlington Jun 02 '11 at 11:03
  • Hi Stephen, that question was asked in year 2009 so I thought there must be something else that Apple support to deal with Push Notification badge counter. I couldn't understand how could I increment the counter while I don't have control over my application running in background? I definitely can't do things only from server. There has to be something on client as well that I am not getting and trying to learn. – Paresh Masani Jun 02 '11 at 13:23
  • Questions and answers can be updated, wiki-style, so there's no need to re-ask questions. Especially when the answers are still relevant. – Stephen Darlington Jun 02 '11 at 13:31
  • All right Stephen. I will take care going forward. Thank you. – Paresh Masani Jun 02 '11 at 14:35

1 Answers1

8

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.

EDIT: You can set the badge counter using:

[UIApplication sharedApplication].applicationIconBadgeNumber = badgeCount;

Every time you do, you should send badgeCount to the server, so that the server knows the current count.

Erik B
  • 40,889
  • 25
  • 119
  • 135
  • I am sure it shouldn't be a problem but I am new to it and trying to learn so if you could provide your ideas or any documentation that would be really helpful for me. Please also see my reply to Stephen's comment. Thank you. – Paresh Masani Jun 02 '11 at 13:26
  • @AppleDeveloper Updated my answer to provide information on how to set the badge count locally. I don't know enough about your server to give you any specifics on how to send the badge count to your server. – Erik B Jun 02 '11 at 13:58
  • ...so does that mean I might need to send different badge counters to different devices? – Paresh Masani Jun 02 '11 at 14:34
  • @AppleDeveloper Do you mean that all your users have the same badge count? I mean I would like to see my own badge count and not someone else's. – Erik B Jun 02 '11 at 14:41
  • Off course you will see your count olny :) Suppose two people got the 5 messages and count is set to 5. Now one of them seen the message and counter reset to 0. This should be recorded by server as per your previous post. Now if I want to send one more message, one will have badge count 1 and another will have badge count 6 in my push notification payload. Am I correct? – Paresh Masani Jun 02 '11 at 14:49
  • 1
    I didn't like the way of this implementation. This should happen automatically and iPhone OS should be taken care of this. Why do you need to synchronize the counter with your database? I don't see any plus point there. I might be missing something obvious though...!! – Paresh Masani Jun 02 '11 at 14:52
  • @AppleDeveloper In the case of poor connectivity I suppose your push notification could be lost somewhere and your badge count would get out of sync. Also if the same user have multiple devices and he reads his messages on one device then the badge count wouldn't be synchronized with the other devices. However, what reasons Apple have isn't really important. Apple is God in this case and decides the faith of us mere mortals. You could always pray for change, i.e., post a bug report, but just like God, Apple will feel free to ignore it. – Erik B Jun 02 '11 at 15:06
  • Thank you Erik. I think we are good to close this discussion! – Paresh Masani Jun 02 '11 at 15:41
  • @AppleDeveloper thanks for bringing up this issue and telling the truth: this is insane that they do not allow a simple increment value. – Nicholas Petersen Aug 01 '13 at 19:23