在Xcode 8 / Swift 3.0中注冊推送通知?我正在嘗試讓我的應用程序在Xcode 8.0中運行,并且遇到了錯誤。我知道這個代碼在以前版本的swift中運行良好,但我假設在新版本中更改了代碼。這是我正在嘗試運行的代碼:let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil) UIApplication.sharedApplication().registerUserNotificationSettings(settings)UIApplication.shared().registerForRemoteNotifications()我得到的錯誤是“參數(shù)標簽”(forTypes:,categories :)'與任何可用的重載都不匹配“是否有一個不同的命令,我可以嘗試使其工作?
3 回答

鴻蒙傳說
TA貢獻1865條經(jīng)驗 獲得超7個贊
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { if #available(iOS 10, *) { //Notifications get posted to the function (delegate): func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void)" UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in guard error == nil else { //Display Error.. Handle Error.. etc.. return } if granted { //Do stuff here.. //Register for RemoteNotifications. Your Remote Notifications can display alerts now :) DispatchQueue.main.async { application.registerForRemoteNotifications() } } else { //Handle user denying permissions.. } } //Register for remote notifications.. If permission above is NOT granted, all notifications are delivered silently to AppDelegate. application.registerForRemoteNotifications() } else { let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) application.registerForRemoteNotifications() } return true}
- 3 回答
- 0 關注
- 667 瀏覽
添加回答
舉報
0/150
提交
取消