Код: Выделить всё
didRegisterForRemoteNotificationsWithDeviceTokenЭто то, что я пробовал до сих пор:
В DidFinishLaunchingWithOptions
Код: Выделить всё
FirebaseApp.configure()
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.badge, .alert, .sound]) {
(granted, error) in
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
//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)
application.registerUserNotificationSettings(setting)
application.registerForRemoteNotifications()
//UIApplication.shared.registerForRemoteNotifications()
}
Код: Выделить всё
private func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
Messaging.messaging().apnsToken = deviceToken as Data
print("Registered Notification")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print(error.localizedDescription)
print("Not registered notification")
}
- Я пробовал на реальном устройстве ни один из методов не вызывается.
- Я пробовал на симуляторе, работает ли код или нет, метод DidFailToRegisterForRemoteNotificationsWithError вызывается
с ошибкой. (Это означает, что код в порядке) - Я дважды проверил сертификаты и повторно сгенерировал файл обеспечения после включения push-уведомлений в
возможностях. - Я также добавил фоновые режимы -> удаленные уведомления включено.
- Я пробовал использовать устаревшую сборку, но тоже безуспешно.
- Я много раз пытался переустановить приложения, но ничего не получалось.
- FirebaseAppDelegateProxyEnabled — это в plist установлено значение NO, все равно безуспешно.
- Также обновил модули, все равно безуспешно.
Подробнее здесь: https://stackoverflow.com/questions/558 ... ed-swift-5