Я использую push-уведомления в своем проекте с APNS.Push-уведомления хорошо работали, прежде чем добавить и настроить Firebase SDK.Я заметил, что после добавления Firebase функция: didRegisterForRemoteNotificationsWithDeviceToken
не вызывается.
Я не знаю, есть ли что-то, что мне нужно отключить в Firebase, если я удалю настройку Firebase (FirebaseApp.configure ()), функция didRegisterForRemoteNotificationsWithDeviceToken
вызывается снова.
Мой код:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// ... existing code ...
registerForPushNotifications()
return true
}
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
guard granted else { return }
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
}
let token = tokenParts.joined()
print("Device Token: \(token)")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register: \(error)")
}