在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()我得到的错误是“参数标签”(forTypes:,categories :)'与任何可用的重载都不匹配“是否有一个不同的命令,我可以尝试使其工作?
3 回答
鸿蒙传说
TA贡献1865条经验 获得超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 关注
- 641 浏览
添加回答
举报
0/150
提交
取消