Sending test push messages with firebase (@capacitor/push-notifications, @capacitor-community/fcm)

I implemented capacitor push notifications with @capacitor/push-notifications and @capacitor-community/fcm. Now I try to send test messages by FCM token with the firebase test message feature:

I use the following tokens:
token_push_notification: token.value in registration listener of PushNotifications
token_fcm: r.token of promise return from FCM.getToken()

No error messages while registering

Messaging from firebase(sending test message with token) has this result:
token_push_notification → android: Works fine - Shows message in top bar when app is closed, and triggers pushNotificationReceived when app is running.
token_fcm → android: Nothing happens on device
token_push_notification → ios: Nothing happens on device
token_fcm → token_fcm: Nothing happens on device

Can somebody tell me how to debug this? Is it possible at all to send test messages with the token from @capacitor-community/fcm?

One thing to not: The app is not yet reviewed and release for AppStore. May this be the reason, why it does not work on iOs?

I just implemented push notifications using @capacitor/push-notifications and did find that Firebase needed the FCM token and not the raw APNS token for iOS. I am not using @capacitor-community/fcm so can’t speak on that.

To get the FCM token you need the following code in your AppDelegate.swift file:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
        Messaging.messaging().token(completion: { (token, error) in
            if let error = error {
                NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
            } else if let token = token {
                NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
            }
          })
    }

Reference

Also to note, assuming you are using a physical iOS device? Push notifications don’t work in the iOS emulator. Apple has to make everything difficult don’t they especially when you don’t own a Mac or iPhone :frowning_face:

Thank you! I Implemented your code, the token I get is not not malformed anymore. But it still does not work. Maybe because it is in livereload mode? Or because the app is not live in the ApppStore?

And yes, it’s hard. I had to buy a MacMini and an iPad. It is practically impossible to release an AppStore App without these devices. Apple knows how to run it’s business :slight_smile:

Nice! One step closer. I am not sure about being live in the App Store. Mine works just being in TestFlight, both under Internal Testing and External Testing. Internal Testing doesn’t require an app review. Capacitor’s doc mentions either a Dev or Prod cert/provisioning profile so seems like it should work without even being in TestFlight.

Yeah, I will probably go the MacMini route if our app takes off. Right now I use macincloud.com.

Ok, found it: I just did not add the APN Key, like described here: Capacitor - build cross platform apps with the web
Now it works. It’s always a good idea to read the docs carefully :wink:

1 Like