Так что я нашел решение, Каждый раз после получения свежего токена FCM от обратного вызова.
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)
Мы должны перерегистрировать удаленное push-уведомление.
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.badge, .alert, .sound]) {
(granted, error) in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
//print("APNS Registration failed")
//print("Error: \(String(describing: error?.localizedDescription))")
}
}
} else {
let type: UIUserNotificationType = [UIUserNotificationType.badge, UIUserNotificationType.alert, UIUserNotificationType.sound]
let setting = UIUserNotificationSettings(types: type, categories: nil)
UIApplication.shared.registerUserNotificationSettings(setting)
UIApplication.shared.registerForRemoteNotifications()
}
FirebaseMessagingперенастроит новый токен FCM с токеном устройства.
Примечание: Нет, необходимо явно указать токен устройства.Поскольку FirebaseMessaging использует метод swizzling, он автоматически получит его из метода делегата.
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)