ios设置角标不显示的问题

1.ios设置角标个数的方法

方法1:

  [[UIApplication sharedApplication] setApplicationIconBadgeNumber:99];

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];

方法2:

  [UIApplication sharedApplication].applicationIconBadgeNumber = 99

  当角标个数为0的时候,设置个数为0,系统会自动设置角标不显示

2.角标设置之后不显示的原因

如果项目中集成了友盟的推送,那就是友盟推送默认清空角标,需要将默认清空关闭。调用此方法:

[UMessage setBadgeClear:NO];

3.需要提前设置权限

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    [application registerForRemoteNotifications];

    if (@available(iOS 10.0, *)) {

        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

        center.delegate = self;

        [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge|UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {

            if (!error) {

                NSLog(@"请求权限成功!");

            }

        }];

        [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {

            NSLog(@"%@",settings);

        }];

        [[UIApplication sharedApplication] registerForRemoteNotifications];

    } else {

        // Fallback on earlier versions

    }

你可能感兴趣的:(ios设置角标不显示的问题)