【发布时间】:2014-07-18 20:22:56
【问题描述】:
我在Updating application badge at midnight with options: app not launched or in background, badge number can decrease 上看过问题 和Changing application icon badge when notification arrives 和Push Notification Badge Count Not Updating 和Update badge icon when app is closed 等等,但我遇到的问题与当应用程序处于后台并且推送通知到达时,应用程序徽章图标未更新时相同。
我已经检查了所有的可能性。我的代码是:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UIApplicationState appState = UIApplicationStateActive;
if ([application respondsToSelector:@selector(applicationState)]) {
appState = application.applicationState;
}
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
NSLog(@"remote notification: %@",[userInfo description]);
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo valueForKey:@"aps"] valueForKey:@"badge"] integerValue];
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
message:message
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
是的,当应用程序处于前台时它工作正常,然后它显示警报正常。但是当应用程序在后台时,既没有发生任何事件,也没有更新应用程序徽章图标。我还设置了后台模式,如ios7.1: push notification badge update issue 所示,我还测试了应用程序在前台时应用程序徽章图标是否正确接收并打印在 NSLog 中。当应用程序在后台运行并且工作正常时,我需要将未读消息设置为徽章图标,但是当任何新的推送通知到达时应该更新它。请建议我选择。
【问题讨论】:
-
必须从服务器端管理,而不是从iOS端管理。
-
@iPatel 是的,但是为什么设置了 aps->badge 时徽章图标没有更新?通知到达时,徽章图标应设置为 aps->badge 的值,并且应用程序无法处理通知,因为它在后台
-
服务器端代码没问题,我已经测试过了。它给出了徽章计数的完美计数结果,我已经通过调试进行了检查,当应用程序处于前台时它给出了完美的结果。但是当通知到达并且应用程序处于后台时,它应该更新应用程序图标徽章。
标签: ios iphone notifications push-notification badge