【发布时间】:2011-05-05 09:21:58
【问题描述】:
我有一个使用 PUSH 的应用程序。但是当应用程序处于非活动状态/在后台时,我遇到了一个问题。 当 PUSH 消息到来并且用户点击关闭时,徽章会设置在应用程序图标上。
但我也想在 tabBarItem 上设置一个徽章。 我有这段代码可以保存 PUSH
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateInactive) {
//Save the PUSH until the app is active.
newPush = [userInfo copy];
}
}
在:
- (void)applicationDidBecomeActive:(UIApplication *)application
我有以下代码:
//Check if there is new PUSH messages.
if (newPush!=nil) {
//There is a new PUSH!
NSInteger badge = [[[newPush objectForKey:@"aps"] objectForKey:@"badge"] intValue];
if (badge > 0) {
//Set badge-numbers to 'badge'
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];
[[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:[NSString stringWithFormat:@"%d",badge]];
}
else {
//Set badge-numbers to zero
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:nil];
}
}
我在应用程序处于活动状态时处理 PUSH 的代码工作正常,并且在应用程序图标和 tabBarItem 上都设置了徽章。
有人知道怎么了?
提前致谢!
【问题讨论】:
-
我很确定除非应用程序处于活动状态,否则您不会收到 didReceiveRemoteNotification。或者在警报上单击打开时
标签: iphone apple-push-notifications