当应用程序处于推送通知的后台时,我的应用程序徽章数量不会增加。仅当第一次推送通知时,计数才会增加1,并且始终将徽章计数保留为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;
}
}
我看到很多关于推送通知和证书的类似问题,只是想知道这是从哪里来的。 – zaph
您的服务器发送给APNS的有效负载是什么? – Moxy
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];我使用的是以上有效载荷 – user2230971