0

Estoy recibiendo mensajes de fireabse para notificaciones con APNs, en firebase tengo el certificado de APNs key, con el mismo id en el proyecto de Xcode en Firebase que se extrae desde Apple Developer.

Pero no se porque puede estar pasando esto y sale este error y se me esta registrando dos tokens en la extension de Messaging:

extension AppDelegate : MessagingDelegate {
  func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {}}

APNS device token not set before retrieving FCM Token for Sender ID '########'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.

Agrego lo que tengo en el AppDelegate

import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate{

    var firebaseToken: String = ""
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        FirebaseApp.configure()
        self.registerForFirebaseNotification(application: application)
        Messaging.messaging().delegate = self
        return true
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
    }

    func registerForFirebaseNotification(application: UIApplication) {
        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self

            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions,
                completionHandler: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings =
                UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }

        application.registerForRemoteNotifications()
    }
    
}

extension AppDelegate: MessagingDelegate, UNUserNotificationCenterDelegate {

//MessagingDelegate
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        self.firebaseToken = fcmToken!
        print("Firebase token: \(fcmToken)")
    }

    //UNUserNotificationCenterDelegate
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        print("APNs received with: \(userInfo)")
     }
}
7
  • Aclaro no me están llegando notificación ni por api ni por consola de Firebase
    – David Leon
    el 7 oct. 2021 a las 15:14
  • Estás haciendo pruebas en el simulador o en el iPhone? Si es en el iPhone, cómo obtienes el ssuid?
    – Bicho
    el 7 oct. 2021 a las 15:53
  • @Bicho, estoy haciendo pruebas desde celular fisico, antes no me aparecía esto pero desde ayer me empezó a salir ese mensaje y ya no me llegan mensajes de cloud messaging de firebase. El ssuid?, se refiere al sender Id?
    – David Leon
    el 7 oct. 2021 a las 16:06
  • @Bicho, no se cómo saber si esta almacenado en firebase, en caso si eso es lo que esta afectando como lo puedo hacer desde el AppDelegate?.
    – David Leon
    el 7 oct. 2021 a las 16:17
  • @Bicho yo realice esta misma configuración : firebase.flutter.dev/docs/messaging/apple-integration
    – David Leon
    el 7 oct. 2021 a las 16:23

1 respuesta 1

1

La solución fue:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Messaging.messaging() .setAPNSToken(deviceToken, type: MessagingAPNSTokenType.unknown) }

2
  • Puedes marcar como solución a tu respuesta, así ayudas a otros con el mismo problema.
    – Bicho
    el 11 oct. 2021 a las 12:51
  • Para mi la clave ha sido la función didRegisterForRemoteNotificationsWithDeviceToken
    – Andrey
    el 30 jun. 2022 a las 16:06

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.