下面是故事。我最终继承了一个我试图帮助支持的iphone应用程序。与swift相比,我更像是一个python开发人员,但我边学习边学习。我修复了这个应用程序的其他一些问题,但我被徽章通知卡住了。显然,"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:]和-[UNUUserNotificationCenter setNotificationCategories:]我找到了苹果的文档https://developer.apple.com/documentation/usernotifications/unauthorizationoptions
如何将其放入UIUserNotificationType数组?如有任何帮助,我们将不胜感激。谢谢
如何将其放入UIUserNotificationType数组?
您不会这样做,因为整个UIUserNotificationSettings
枚举都已被弃用。来自UIUserNOtificationSettings
文档:
重要信息:UIUserNotificationSettings在iOS 10中已弃用。请改用UNNotificationSettings。UIUserNotificationSettings对象封装了应用程序可以向用户显示的通知类型。
此外,根据您的错误消息,registerUserNotificationSettings()
也不推荐使用。registerForRemoteNotifications()
的文档解释说,如果你想显示徽章等,你需要调用UNUserNotificationCenter
的requestAuthorization(options:completionHandler:)
方法。