简体   繁体   English

Parse.com推送通知徽章值

[英]Parse.com push notification badge value

I use parse.com and the iOS Parse Framework in an iOS app. 我在iOS应用程序中使用parse.comiOS Parse Framework 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. 我想向频道发送推送通知,但我希望将徽章的值设置为1 ,即使用户收到多个通知也是如此。

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键的值:

badge: (iOS only) the value indicated in the top right corner of the app icon. 徽章:( 仅限iOS)应用程序图标右上角显示的值。 This can be set to a value or to Increment in order to increment the current value by 1. 这可以设置为值或增量,以便将当前值增加1。

So obviously, the value @"Increment" works fine, but I want to always set the badge value to " 1 ". 显然,值@"Increment"工作正常,但我想始终将徽章值设置为“ 1 ”。

What is the correct syntax ? 什么是正确的语法? I can't seem to find it ! 我似乎无法找到它!

You should use an NSNumber. 你应该使用NSNumber。 Ie

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

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

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