iOS 之不同系统版本提示用户授权通知中心方法


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        // ......

        //
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (success, error) in
                print("获取用户授权通知中心" + (success ? "成功" : "失败"))
            }
        } else {
            // Fallback on earlier versions
            let notificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound],
                                                                  categories: nil)
            application.registerUserNotificationSettings(notificationSettings)
        }

}

你可能感兴趣的:(iOS 之不同系统版本提示用户授权通知中心方法)