在iOS 10中不推荐使用UIUserNotificationSettings

Pra*_*rav 28 xcode apple-push-notifications swift ios10 xcode8

我正在寻找在iOS 10中实现UIUserNotificationSettings的替代方法.

Apple文档提供了以下框架以供进一步使用.UNNotificationSettings链接在这里.

是否有人可以帮助我使用示例代码来使用UNNotificationSettings而不是UIUserNotificationSettings来实现下面的代码

let notificationSettings = UIUserNotificationSettings(
        forTypes: [.Badge, .Sound, .Alert], categories: nil)
    application.registerUserNotificationSettings(notificationSettings)
Run Code Online (Sandbox Code Playgroud)

Ole*_*huk 57

注册通知您应该实现此代码:

import UserNotifications

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { 
 (granted, error) in
 //Parse errors and track state
}
Run Code Online (Sandbox Code Playgroud)

资源包含其他信息.

  • 不要忘记此代码下面的“ application.registerForRemoteNotifications()”。 (5认同)
  • 另外不要忘记链接 UserNotifications.framework 和 @import UserNotifications。 (2认同)