【问题标题】:Swiftt Badge Notifications Depreciated after iOS10Swift 徽章通知在 iOS 10 之后贬值
【发布时间】:2019-11-20 23:15:40
【问题描述】:

所以这就是故事。我最终继承了一个我试图帮助支持的 iphone 应用程序。我更像是一个 python 开发人员,而不是 swift,但我边走边学。我修复了这个应用程序的其他一些问题,但我卡在徽章通知上。显然,“UIUserNotificationType”在 iOS 10 之后已弃用。谁能给我指点教程或任何好的文档?

我需要更新以下方法:

 func initialize(application:UIApplication){

                 let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
                 let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
                 application.registerUserNotificationSettings(pushNotificationSettings)
                 application.registerForRemoteNotifications()
}

我遇到以下 3 个问题:

'UIUserNotificationType' 在 iOS 10.0 中已弃用:使用 UserNotifications Framework 的 UNAuthorizationOptions'

“UIUserNotificationSettings”在 iOS 10.0 中已弃用:使用 UserNotifications Framework 的 UNNotificationSettings”

'registerUserNotificationSettings' 在 iOS 10.0 中已弃用:使用 UserNotifications Framework 的 -[UNUserNotificationCenter requestAuthorizationWithOptions:completionHandler:] 和 -[UNUserNotificationCenter setNotificationCategories:] 我找到了苹果文档https://developer.apple.com/documentation/usernotifications/unauthorizationoptions

我怎样才能把它放到 UIUserNotificationType 数组中?任何帮助,将不胜感激。谢谢!

【问题讨论】:

    标签: ios swift iphone apple-push-notifications


    【解决方案1】:

    我怎样才能把它放到 UIUserNotificationType 数组中?

    您不会,因为整个 UIUserNotificationSettings 枚举已被弃用。来自UIUserNOtificationSettings 文档:

    重要提示: UIUserNotificationSettings 在 iOS 10 中已弃用。请改用 UNNotificationSettings。 UIUserNotificationSettings 对象封装了您的应用可以向用户显示的通知类型。

    此外,根据您的错误消息,registerUserNotificationSettings() 也已弃用。 registerForRemoteNotifications() 的文档解释说,如果你想显示徽章等,你需要调用 UNUserNotificationCenterrequestAuthorization(options:completionHandler:) 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 2018-09-08
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多