capacitor-community / fcm

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

Conflicting with Capacitor Push notification #11

Closed mrahmadt closed 5 years ago

mrahmadt commented 5 years ago

Hello

with the new Capacitor Push notification that supports FCM on iOS (which can not be disabled for some reason!), I found 2 issues when you implement capacitor-fcm

Any way to fix this?

PS: the current Capacitor Push notification implementation does not return FCM token, only apple token

stewones commented 5 years ago

Thats weird, can you share a reproducible example?

mrahmadt commented 5 years ago

Hi

Nothing special, I just installed capacitor-fcm and capacitor

$ ionic info

Ionic:

Ionic CLI                     : 5.2.3 (/usr/local/lib/node_modules/ionic)
Ionic Framework               : @ionic/angular 4.6.2
@angular-devkit/build-angular : 0.801.1
@angular-devkit/schematics    : 8.1.1
@angular/cli                  : 8.1.1
@ionic/angular-toolkit        : 2.0.0

Capacitor:

Capacitor CLI   : 1.1.0
@capacitor/core : 1.1.0

Utility:

cordova-res : not installed
native-run  : not installed

System:

NodeJS : v11.4.0 (/usr/local/Cellar/node/11.4.0/bin/node)
npm    : 6.9.0
OS     : macOS Mojave

And in my home page

if (Capacitor.isPluginAvailable('PushNotifications')) {
    PushNotifications.addListener('registration', (token: PushNotificationToken) => {
    console.log("This is APN Token, NOT FCM ON iOS!", token.value);
        },
errRes => {
            console.log(errRes);
        });
    });
    });
    PushNotifications.register();
}
mrahmadt commented 5 years ago

The full code (using ionic starter template)

You will see in the console that registration will return APN token, only getToken will return the FCM token

I suggest that you document this in the readme file.

import { Plugins, Capacitor, PushNotificationToken } from "@capacitor/core";
const { PushNotifications } = Plugins;

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private platform: Platform,
) {
  this.platform.ready().then(() => {
    console.log('platform.ready');
    if (Capacitor.isPluginAvailable('PushNotifications')) {
      PushNotifications.addListener('registration', (token: PushNotificationToken) => {
        console.log('APN Token', token);
        fcm
          .getToken()
          .then(r => console.log('FCM Token', r.token))
          .catch(err => console.log(err));
      });
      PushNotifications.register();
    }
  });
}
}
stewones commented 5 years ago

got it, so it’s working as expected. Capacitor will never send you fcm tokens, that’s why I created this plugin.

Thanks for reporting and feel free to PR if you think that would be really a thing.