【发布时间】:2014-02-24 07:22:55
【问题描述】:
我正在使用此代码。当推送通知到来时,一切正常,但当应用程序处于后台时,徽章数量不会增加。如何解决这个问题呢?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
//UIApplication *application = [UIApplication sharedApplication];
NSInteger badgeNumber = [application applicationIconBadgeNumber];// Take the current badge number
//badgeNumber--; // decrement by one
[application setApplicationIconBadgeNumber:[[[launchOptions valueForKey:@"aps"]valueForKey:@"badge"]integerValue]]; // set ne badge number
NSLog(@"userInfo :%@ %d",launchOptions,[[[launchOptions valueForKey:@"aps"]valueForKey:@"badge"]integerValue]);
return YES;
}
【问题讨论】:
-
您必须在服务器上跟踪徽章编号。无法通过推送通知自动增加数字。如果 Apple 可以添加该功能,那就太棒了。
标签: ios iphone objective-c