當應用程序處於推送通知的後臺時,我的應用程序徽章數量不會增加。僅當第一次推送通知時,計數纔會增加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