小编Dev*_*ngh的帖子

应用程序在后台时如何增加徽章数量

我正在使用此代码。当推送通知出现时,一切正常,但当应用程序在后台时,徽章数量不会增加。如何解决这个问题呢?

- (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)

iphone objective-c ios

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1