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

2 Likes

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!!

1 Like

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);
        });
      });
    });
  }
1 Like

same here, tried all above methods, still not working.

Works on Android without asking for permission, i can also get FCM token, but cannot ask for permission.

using latest version of the plugin: "cordova-plugin-fcm-with-dependecy-updated": "^7.4.0",

Ionic:

   Ionic CLI                     : 5.4.16
   Ionic Framework               : @ionic/angular 5.4.1
   @angular-devkit/build-angular : 0.1000.8
   @angular-devkit/schematics    : 10.2.0
   @angular/cli                  : 10.2.0
   @ionic/angular-toolkit        : 2.3.3

Capacitor:

   Capacitor CLI   : 2.4.2
   @capacitor/core : 2.4.1

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : ios 6.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, cordova-plugin-ionic 5.4.7, (and 6 other plugins)

Utility:

   cordova-res : 0.15.1
   native-run  : not installed

System:

   ios-deploy : 1.9.4
   ios-sim    : 8.0.2
   NodeJS     : v12.5.0 (/Users/user/.nvm/versions/node/v12.5.0/bin/node)
   npm        : 6.14.4
   OS         : macOS Catalina
   Xcode      : Xcode 12.0.1 Build version 12A7300

In ionic 5 its works for me thanks!!

It looks it is not working well for iOS, still recomending it? thank you

I swear it is not working on iOS…

It’s a stretch to say I ever “recommended” it. I have no direct experience with anything Firebase. I was just reading the changelog and responding to a specific problem with a particular method that was added after this thread was already old.

Thank you anyway sir

don’t worry for ios, use push plugin then get to perfect your desire. it was the same issue for then i done it with both just checked the platform