ios - 未收到设备 token

标签 ios swift push-notification

iPhone 设备没有从我的应用程序接收设备 token 。

didRegisterForRemoteNotificationsWithDeviceToken

虽然我在

中有以下代码,但方法没有被调用
didFinishLaunch

方法。

didFinishLaunch方法中:

let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
UIApplication.shared.registerForRemoteNotifications()

注意:

  1. notificationSettings 方法被调用。但不是为远程通知调用的 didRegisterdidFail 方法。
  2. 我使用的是装有 iOS 9 的 iPhone 6s。

获取设备 token 需要检查什么?

最佳答案

您正在使用 UNUserNotificationCenter 但它仅在您的设备运行 iOS 10 或 10+ 时有效。

对于 iOS 9 你需要下面的代码注册推送通知

UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
UIApplication.shared.registerForRemoteNotifications()

您可以根据 iOS 版本添加条件,例如 @Kamalesh answer。

关于ios - 未收到设备 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46730248/

相关文章:

ios - 如何在接收设备上用另一个推送通知替换一个推送通知?

iphone - 文本滚动到 UITextView 框边界之外

ios - 停止动态表重新加载 IndexPath - Swift

swift - 在 ForEach/ZStack (SwiftUI) 中将表达式分解为不同的子表达式

ios - 使用 Swift 从 AppDelegate 更改 UINavigationBar 后退按钮文本和字体

notifications - 使用 Firebase 实时推送通知

ios - 我如何在 UITabbar 顶部添加一个按钮

ios - 绑定(bind) Objective-C 包时出错

ios - 更改单元格删除按钮的文本

ios - 当应用程序未在 React-Native firebase 中运行时如何设置通知声音