iOS8.0之后,设置APP 的badgeNumber,需要用户授权才能显示
import UserNotifications
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .carPlay, .sound], completionHandler: { (success, error) in
print("授权" + (success ? "成功" : "失败"))
})
} else {
// iOS 10 以下
//取得用户授权显示通知【上方的通知条、声音、badgeNumber】
let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories:nil)
application.registerUserNotificationSettings(settings)
}
return true
}