UIApplication:setApplicationIconBadgeNumber函数,来设置脚标如果是远程的aps,例如Jpush,需要后台赋值badge,传给苹果服务器,实现自动加。当然,这种情况在你进入程序的时候,仍需
调用UIApplication:setApplicationIconBadgeNumber函数,来设置脚标。
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:99]
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count]
[UIApplication sharedApplication].applicationIconBadgeNumber = 99
当角标个数为0的时候,设置个数为0,系统会自动设置角标不显示
如果项目中集成了友盟的推送,那就是友盟推送默认清空角标,需要将默认清空关闭。调用此方法:
[UMessage setBadgeClear:NO]
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
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)