简体   繁体   中英

Parse.com push notification badge value

I use parse.com and the iOS Parse Framework in an iOS app. I want to send a push notification to a channel, but I would like the value of the badge to be set to 1 , even if the user receives multiple notifications.

Here is the code used to send the notification, taken from the documentation :

NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
    @"Here is the content of the notification !", @"alert",
    @"Increment", @"badge",
    @"cheering.caf", @"sound",
    nil];
PFPush *push = [[PFPush alloc] init];
[push setChannels:[NSArray arrayWithObjects:@"A Channel", nil]];
[push setData:data];
[push sendPushInBackground];

Here is what they say (go to "Sending options" > "Customizing your notifications") about the value of the badge key in the dictionary :

badge: (iOS only) the value indicated in the top right corner of the app icon. This can be set to a value or to Increment in order to increment the current value by 1.

So obviously, the value @"Increment" works fine, but I want to always set the badge value to " 1 ".

What is the correct syntax ? I can't seem to find it !

You should use an NSNumber. Ie

[push setData:@{
    @"alert": @"Here is the content of the notification !",
    @"badge": @1,
    @"sound": @"cheering.caf"}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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