capacitor-community / fcm

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

FCM Push Notification are not working in IOS. #90

Closed Saqib92 closed 2 years ago

Saqib92 commented 2 years ago

Describe the bug Everythign is Perfectly Works on Android but in IOS i am having Following Error: APNS device token not set before retrieving FCM Token for Sender ID 'mySenderId'. 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.

Expected behavior It should work fine I have setup everything correctly (that's what i assume :p)

Desktop (please complete the following information):

Smartphone (please complete the following information):

Followed this This Tutorial also researched from other resources e.g: this

halomakes commented 2 years ago

I was getting this error too. I moved my call to FCM.getToken() to the callback for PushNotifications.addListener('registration') and that made this error go away but I am still not getting notifications on iOS. Tried sending notifications by device token ID and by firebase topic ID to no avail.

stewones commented 2 years ago

hello there. it's impossible to know without a reproducible example, where we can download and try.

it works using the example application

can you please try on both latest capacitor + plugin?

Saqib92 commented 2 years ago

here is the repo: https://github.com/Saqib92/cap-push-issue

Saqib92 commented 2 years ago

I was getting this error too. I moved my call to FCM.getToken() to the callback for PushNotifications.addListener('registration') and that made this error go away but I am still not getting notifications on iOS. Tried sending notifications by device token ID and by firebase topic ID to no avail.

this is how i made it Work:

PushNotifications.requestPermissions().then((permission) => {
        if (permission.receive == "granted") {
          // Register with Apple / Google to receive push via APNS/FCM
          if(Capacitor.getPlatform() == 'ios'){
            PushNotifications.register().then((res)=>{
              console.log('From Regisiter Promise', res)
            })
            PushNotifications.addListener('registration', (token: Token)=>{            
              FCM.getToken().then((result) => {
                this.remoteToken = result.token;
              }).catch((err) => console.log('i am Error' , err));
            })
          }else{
            FCM.getToken().then((result) => {
              this.remoteToken = result.token;
            }).catch((err) => console.log('i am Error' , err));
          }
        } else {
          // No permission for push granted
          alert('No Permission for Notifications!')
        }
      });