capacitor-community / fcm

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

didReceiveRegistrationToken Error #79

Closed mattnickcodes closed 3 years ago

mattnickcodes commented 3 years ago

After installation of @capacitor/push-notifications and @capacitor-community/fcm I am able to receive push notifications but I am not able to receive a registration token to send messages to individual users.

Here is the error I'm getting:

stewones commented 3 years ago

I suspect you didn't update AppDelegate for Capacitor v3

Take a look in the repo example and review Capacitor's migration guide. There was some breaking changes.

https://github.com/capacitor-community/fcm/blob/50ae478d3e4a6a70b3c973dc9c18a158a615e2a8/example/ios/App/App/AppDelegate.swift#L71

stewones commented 3 years ago

Can you provide a reproducible example?

mattnickcodes commented 3 years ago

The solution is making sure the FCM.getToken() function is not called/triggered by any of the PushNotifications functions.

The code I wrote here causes this particular error. I believe it happens because the registration event is being fired before FCM initializes. PushNotifications.addListener('registration', () => { FCM.getToken().then((token: any)=>this.saveToken(token.value)) });

stewones commented 3 years ago

Glad you figured it out.