capacitor-community / fcm

Enable Firebase Cloud Messaging for Capacitor apps
https://capacitor.ionicframework.com/docs/
MIT License
243 stars 83 forks source link

Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token. #26

Closed TravBradfield closed 4 years ago

TravBradfield commented 4 years ago

Hi There,

Great plugin. I've built a series of apps and happily integrated this plugin. However today I'm struggling to get iOS to work. I've followed all of the steps and now when running the application on an iPhone Xcode gives me the following error:

The object <FCM: 0x2810fec00> does not respond to -messaging:didReceiveRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token.

TravBradfield commented 4 years ago

So I figured out what my issue was. I had not called Plugins.PushNotifications.register();

Once I had done that then I was in the clear.

stewones commented 4 years ago

closing as it seem to be sorted out

Simbaclaws commented 3 years ago

Sorry for reopening this issue but I am getting the same error message in my console and PushNotifications.register returns an empty value. I am calling it like this:

PushNotifications.requestPermission().then( result => {
      if (result.granted) {
        // Register with Apple / Google to receive push via APNS/FCM
        PushNotifications.register().then((value) => {
          console.log("registration token: ", value);
        }).catch((error) => {
          console.error(error);
        });
      } else {
        // Show some error
        console.error("registration failed");
      }
    });

The request permission dialog comes up and when I click allow it tells me: registration token: {}

Artkoch commented 3 years ago

I'm having the same issue. I init it in the index.tsx the following way

const setupPushNotifications = async () => {
  if (!isPushNotificationsAvailable) return;
  const primission = await PushNotifications.requestPermission();

  if (primission.granted) {
    PushNotifications.addListener("registration", (token) => {
      console.log("FCMPlugin.getToken()", FCMPlugin.getToken());
      console.log("registration token: ", token);
    });

    PushNotifications.register();
  }
};

setupPushNotifications();

My log, looks like this image

jcardus commented 3 years ago

hey @Artkoch, FCMPlugin.getToken returns a promise, if you wait for it you should get your firebase token.