【发布时间】:2013-09-29 16:32:07
【问题描述】:
当应用程序在后台进行推送通知时,我的应用程序徽章计数不会增加。计数仅在第一个推送通知时增加 1,并且始终保持徽章计数为 1,如果我收到超过 1 个通知,徽章计数也仅保留 1 . 下面是我的代码
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSString *message = nil;
id alert = [userInfo objectForKey:@"aps"];
if ([alert isKindOfClass:[NSString class]]) {
message = alert;
}
else if ([alert isKindOfClass:[NSDictionary class]]) {
message = [alert objectForKey:@"alert"];
}
if (alert) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"xyz"
message:message
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
alertView.tag=2525;
[alertView show];
}
}
-(void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag==2525) {
[UIApplication sharedApplication].applicationIconBadgeNumber =
[UIApplication sharedApplication].applicationIconBadgeNumber-1;
}
}
【问题讨论】:
-
我看到很多关于推送通知和证书的类似问题,只是想知道这是来自哪个类。
-
您的服务器向 APNS 发送什么有效负载?
-
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];我正在使用上述有效载荷
-
我的意思是你的服务器正在发送的数据,它为徽章设置了什么值?
-
aps = { alert = "第三次测试";徽章 = 1; sound = "sound.caf"; };每次我得到这个响应表单服务器。但是我在点击通知后得到这个
标签: ios xcode push-notification apple-push-notifications badge