3

I'm building an app with the Corona SDK which has a QuickBlox back end. I have one final technical challenge - how can I get the badge counter to increment each time a push notification is received? I am using the REST API to send the messages.

Sameer Singh
  • 1,358
  • 1
  • 19
  • 47

2 Answers2

1

To manage badge counter in Push Notification you should send Push Notification with proper badge value. iOS device doesn't increment it automatically each time you received new push message

To send push from iOS device with particular badge counter you should use this code:

NSMutableDictionary *payload = [NSMutableDictionary dictionary];
NSMutableDictionary *aps = [NSMutableDictionary dictionary];
[aps setObject:@"default" forKey:QBMPushMessageSoundKey];
[aps setObject:@"This is Push Notification, baby!" forKey:QBMPushMessageAlertKey];
[aps setObject:@"5" forKey:QBMPushMessageBadgeKey];
[payload setObject:aps forKey:QBMPushMessageApsKey];

QBMPushMessage *message = [[QBMPushMessage alloc] initWithPayload:payload];

// Send push
[QBMessages TSendPush:message toUsers:@"218650" delegate:self];

You will receive push message with badge value = 5

Also you can send push from Admin panel and manage badge value as well https://www.evernote.com/shard/s216/sh/7e53a5e3-c24b-4ae9-b4c4-855dd4f41370/b404dcb788992fb1a8dabe1bf0fbcc0f

Rubycon
  • 18,156
  • 10
  • 49
  • 70
  • Ok, but this is a Corona project not xCode. So essentially I must store the badge count on the database and add 1 to this to make it work? – user2747184 Sep 05 '13 at 19:35
  • @IgorKhomenko, I think there's some mess. I'm getting badge count updated when app received push from QuickBlox server (not sent via code).. but how do I manage the badge when a push would get send by me (via code). How do I know, there are 6 badge value (from server) and one is from my side so I've to pass 7 for that particular user. – Hemang May 01 '15 at 06:02
1

Sending QBMPushMessageBadgeKey as a string parameter (for iOS7 at least) won't update icon badge if app is running in background.

You should send it as a NSNUmber and it will work pretty well, either app is running in background or foreground:

[aps setObject:@5 forKey:QBMPushMessageBadgeKey];
Marcos Reboucas
  • 3,409
  • 1
  • 29
  • 35