Ionic 5, FCM plugin does not request permissions to receive push notifications

Hi guys,

My iPhone (a real device) does not ask for permissions to receive push notifications on Ionic 5, cordova-plugin-fcm-with-dependecy-updated 6.0.1, @ionic-native/fcm 5.24.0

hasPermission() returns null

I attempted to downgrade both plugin and @ionic-native/fcm but no succcess. I can get the device token and send a message to the device from the server and Firebase responds with success but since the user did not allow such action, it does nothing.

What I am doing wrong?

It works on Android.

Michals-iMac:appka dash$ ionic info

Ionic:

Ionic CLI : 5.4.16
Ionic Framework : @ionic/angular 5.0.5
@angular-devkit/build-angular : 0.803.25
@angular-devkit/schematics : 8.3.25
@angular/cli : 8.3.25
@ionic/angular-toolkit : 2.2.0

Cordova:

Cordova CLI : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : ios 5.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.0, (and 12 other plugins)

Utility:

cordova-res : 0.12.1
native-run : 1.0.0

System:

ios-deploy : 1.10.0
ios-sim : 8.0.2
NodeJS : v10.15.1 (/usr/local/bin/node)
npm : 6.4.1
OS : macOS Catalina
Xcode : Xcode 11.4.1 Build version 11E503a

1 Like

It also work for cordova-ios 4.5.5

Ionic does not expose the method to request permissions in the new version, so you need to access it like this:

const w: any = window;
w.FCMPlugin.requestPushPermissionIOS(() => {
  console.log('push permissions success');
}, (e) => {
  console.log('push permissions fail', e);
});
8 Likes

First I thought it was FCM plugin issue and I didn’t receive the notification from my iPhone. Then I reached this post and solved my issue with this permission. Thanks buddy!!

Dude you’re the man, thanks for that

Thank you solved it for me!

Sir above code is working with Cordova plugin firebase?

hii michalby,

where to write this code, I mean in which class

@michalby What exactly is const w: any = window;?

When I declare that variable it doesn’t have the requestPushPermissionIOS method.

Forget about it.

I would suggest upgrading @ionic-native/fcm. Current version as I write this is 5.28.0. The discussion in this thread took place before version 5.27.0, in which the method you desire was added. See the CHANGELOG for more details.

Still not work :frowning:
I’m going to migrate to one signal

Try this in your app.component.ts file

import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx';
constructor(
    ...
    private fcm: FCM,
    ...
  ) {
    ...
  }
initializeApp() {
    this.platform.ready().then(() => {
      ...
      this.fcm.requestPushPermission().then(() => {
        this.fcm.getToken().then(token => {
          this.authService.updateFirebaseFCM(token);
        });
      });
    });
  }