Swift使用者通知授權

來源:互聯網
上載者:User

標籤:set   with   setting   ati   return   override   gis   ios   badge   

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

        if #available(iOS 10.0, *) {

            UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .badge, .alert, .carPlay]) { (success, _) in

                if success {

                    print("授權成功")

                } else {

                    print("授權失敗")

                }

            }

        } else {

            let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)

            UIApplication.shared.registerUserNotificationSettings(settings)

        }

        

        // Override point for customization after application launch.

        return true

    }

注意需要

import UserNotifications

Swift使用者通知授權

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.