【问题标题】:UIUserNotificationSettings deprecated in iOS 10 [duplicate]iOS 10 中不推荐使用 UIUserNotificationSettings [重复]
【发布时间】:2017-02-06 03:34:51
【问题描述】:

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

Apple 文档为进一步使用提供了以下框架。链接here中的UNNotificationSettings。

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

let notificationSettings = UIUserNotificationSettings(
        forTypes: [.Badge, .Sound, .Alert], categories: nil)
    application.registerUserNotificationSettings(notificationSettings)

【问题讨论】:

标签: swift xcode apple-push-notifications ios10 xcode8


【解决方案1】:

你应该实现这个代码的通知注册:

import UserNotifications

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

resource 包含其他信息。

【讨论】:

  • 不要忘记在此代码下方application.registerForRemoteNotifications()
  • @iOS.Wolf 仅当您计划拥有不仅仅是本地通知的推送通知时才需要这样做。
  • 别忘了链接 UserNotifications.framework 和 @import UserNotifications。
  • 用 UserNotifications.framework 链接链接的好方法!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-14
  • 2015-07-05
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
相关资源
最近更新 更多