注册拿不到deviceToken
这个代码吃掉下边这个系统回调了,拿不到deviceToken,直接调系统那个 UIApplication.shared.registerForRemoteNotifications()可以拿到。这是为什么?有人遇到么? 跟swiftUI项目有关????
UMessage.registerForRemoteNotifications(launchOptions: launchOptions, entity: createNotificationEntity(), completionHandler: { granted, error in
print("授权状态:\(granted)")
if granted {
DispatchQueue.main.async {
UNUserNotificationCenter.current().delegate = self
UIApplication.shared.registerForRemoteNotifications()
print("授权注册状态:\(UIApplication.shared.isRegisteredForRemoteNotifications)")
}
}
})
// 注册成功回调,获取 deviceToken
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
UMessage.registerDeviceToken(deviceToken)
// 转成16进制字符串
let tokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
// 打印出来
print("✅ deviceToken: \(tokenString)")
}