// #available 是检测设备版本,如果是iOS 10 以上 申请通知权限
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .carPlay, .sound]) { (success, error) in
print("授权" + (success ? "成功" : "失败"))
}
} else {
// iOS 10 以下
let nitifySetting = UIUserNotificationSettings(types: [.badge, .alert, .sound], categories: nil)
application.registerUserNotificationSettings(nitifySetting)
}
网友评论