iOS10 .alert, .badge, .sound等授权

iOS8.0之后,设置APP 的badgeNumber,需要用户授权才能显示
iOS10 .alert, .badge, .sound等授权_第1张图片
1.png
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
    }

你可能感兴趣的:(iOS10 .alert, .badge, .sound等授权)