Firebase Notification To Device with FCM Token Says Sent but not received

后端 未结 4 790
星月不相逢
星月不相逢 2020-12-31 15:54

I am attempting to send a simple push notification from the firebase notification console to a specific device using an FCM token. The firebase notification console shows t

4条回答
  •  無奈伤痛
    2020-12-31 16:40

    Does anyone know why the notification is being marked as sent in the firebase notification console but not showing up on the device?

    Because "sent" does not mean "received".

    Notifications cannot be guaranteed to be received on the device. With basic APNS infrastructure you even cannot get the information if a notifications was received or processed on the device.

    If you don't receive a successfully sent message on the device there can be many reasons. Furthermore, even if you receive a Firebase token, that does not mean that your device can receive the notification in any case.

    To isolate the problem I would suggest to build up the minimal setup and use APNS without Firebase. You could use Terminal or NWPusher (https://github.com/noodlewerk/NWPusher) for sending notifications from your local macOS system and the iOS native remote push notifications framework for receiving notifications.

    Keep care to convert the APNS device token to the correct format required for submitting a notification:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    
        let token = deviceToken.hexEncodedString()
        print("Token: \(token)")
    }
    

    Data extension:

    extension Data {
        func hexEncodedString() -> String {
            return map { String(format: "%02hhx", $0) }.joined()
        }
    }
    

提交回复
热议问题