我正在使用此代码。当推送通知出现时,一切正常,但当应用程序在后台时,徽章数量不会增加。如何解决这个问题呢?
- (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;
}
Run Code Online (Sandbox Code Playgroud)