美文网首页
ios设置角标不显示的问题

ios设置角标不显示的问题

作者: xing_x | 来源:发表于2019-12-10 16:27 被阅读0次

    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设置角标不显示的问题

          本文链接:https://www.haomeiwen.com/subject/pdhoectx.html