iOS如何优雅地消除应用角标详解

2020-01-21 02:47:45王振洲

那么答案就出来了,直接使用 UserNotifications 即可,猜测 badge 应该还是 -1。


- (void)applicationDidEnterBackground:(UIApplication *)application {
 UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
 content.badge = @(-1);
 UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"clearBadge" content:content trigger:nil];
 [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
 }];
}

最后记得不要设置 title,否则会收到空白通知。

参考资料:https://stackoverflow.com/questions/5375355/clear-app-badge-with-local-notifications

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对ASPKU的支持。


注:相关教程知识阅读请移步到IOS开发频道。