danielsogl / awesome-cordova-plugins

Native features for mobile apps built with Cordova/PhoneGap and open web technologies. Complete with TypeScript support.
https://danielsogl.gitbook.io/awesome-cordova-plugins/
Other
2.39k stars 2.43k forks source link

FCM push notifications on iOS do not work with the latest version of the plugin #3395

Closed JuanJo-RC closed 2 years ago

JuanJo-RC commented 4 years ago

I'm submitting a [x] bug report

Current behavior: Since version Version 6.0.0 (04/18/2020) of the cordova-plugin-fcm-with-dependency-updated plugin, On iOS, first run doesn't automatically request Push permission.

The permission, as it is still required, may now be requested from javascript at any moment by executing: FCMPlugin.requestPushPermissionIOS ();

We need that function to be included in the @ionic-native/fcm library, because the method does not currently exist and therefore push notifications are not working on iOS

Expected behavior: To be able to call the requestPushPermissionIOS(); method in the library @ionic-native/fcm

Steps to reproduce: ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated npm install @ionic-native/fcm

import { FCM } from '@ionic-native/fcm'; constructor(private fcm: FCM) {} ...

this.fcm.requestPushPermissionIOS(); (Property 'requestPushPermissionIOS' does not exist on type 'FCM'.)

Ionic info: Ionic:

Ionic CLI : 6.6.0 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 4.11.10 @angular-devkit/build-angular : 0.803.26 @angular-devkit/schematics : 8.1.3 @angular/cli : 8.1.3 @ionic/angular-toolkit : 2.2.0

Cordova: Cordova CLI : 9.0.0 (cordova-lib@9.0.1) Cordova Platforms : ios 5.1.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.0, (and 11 other plugins)

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

System: ios-deploy : 1.10.0 NodeJS : v12.16.2 (/usr/local/bin/node) npm : 6.14.4 OS : macOS Catalina

ghost commented 4 years ago

Hello,

I am experiencing the exact same issue. Works fine on Android as this API is not mandatory.

Ionic:

Ionic CLI : 6.7.0 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.0.7 @angular-devkit/build-angular : 0.803.26 @angular-devkit/schematics : 8.3.26 @angular/cli : 8.3.26 @ionic/angular-toolkit : 2.2.0

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1) Cordova Platforms : android 8.1.0, ios 5.1.1

System:

ios-deploy : 1.10.0 ios-sim : 8.0.2 NodeJS : v13.11.0 (/usr/local/Cellar/node/13.11.0/bin/node) npm : 6.14.4 OS : macOS Catalina Xcode : Xcode 11.4 Build version 11E146

ng22792 commented 4 years ago

Hello, Ionic : 6.7.0 Cordova : 9.0.0 (cordova-lib@9.0.1) Node v10.15.0 npm 6.14.5 Cordova Platforms : ios 5.1.1 Ionic 3 project

I tried this: (in app.component,ts, wherever you are invoking the plugin function of getting the token, above the class, after the imports)

-------------- code starts -------------- declare var FCMPlugin;

// Then right before getToken function PushPromise() { alert("Push Promise"); return new Promise(async (resolve, reject) => { alert("inside promise"); console.log("inside promise");

  FCMPlugin.requestPushPermissionIOS(
    (booleanVal) => { 
      console.log("booleanVal: "+booleanVal);
      alert("booleanVal: "+booleanVal); 
    let success = { err: 'success', status: booleanVal }; 
    resolve(success); 
  }, (err) => { 
     alert(err); let error = { err: err, status: true }; reject(error); 
    }
    );
});

}

async enablePushNotifications() { alert("enablePushNotifications"); if (this.platform.is('ios') || this.platform.is('iOS') || this.platform.is('IOS')) { alert("inside ios platform "); let pushRes = await this.PushPromise().then(

    val => { alert("then val: "+val); return val; }
    ).catch(
      error => { alert("catch error : "+error); return error; }
      );
  alert("enablePushNotifications" + JSON.stringify(pushRes)
  );

  this.fcm.getToken().then(token => {
    alert("token : " + token);
    this.noUti.setDeviceToken(token);
  });

}else{
  this.fcm.getToken().then(token => {
    alert("token : " + token);
    this.noUti.setDeviceToken(token);
  });

}

// this.fcm.onNotification().subscribe(data => { etc etc here..

}

-------------- Code ends --------------

I tried this as https://developer.aliyun.com/mirror/npm/package/cordova-plugin-fcm-with-dependecy-updated this link suggests that "Version 6.0.0 (18/04/2020) On iOS, first run doesn't automatically request Push permission.

The permission, as it is still required, may now be requested from javascript at any moment by executing:

//FCMPlugin.requestPushPermissionIOS( successCallback(), errorCallback(err) ); FCMPlugin.requestPushPermissionIOS();"

And since ts files can call JS functions, I wrote this. This results in the popup for Push Notification permission, which means the FCMPlugin function is being called. But I think thereafter I am unable to handle its response as I dont get alerts post the permission popup. Nor do I get the token since its on async await. Without this code I do get the token generated but Push Notifications arent being delivered. Kindly Help.

johnparkerg commented 4 years ago

I'm experiencing the same issue. +1

QuentinChaumont commented 4 years ago

Having the same issue.

johnparkerg commented 4 years ago

It might help somebody, my problem was that I was using two fcm plugins, this one and fcm-with-dependency-update and mixing them up.

I also realized the firebase notification test isn't as reliable as https://www.apnstester.com/fcm/.

RichardBoyder commented 4 years ago

Hi guys any response on a fix? Im only using the cordova-plugin-fcm-with-dependecy-updated no others and there is no requestPushPermissionIOS available at all.. So same issue.

I downloaded latest plugin "cordova-plugin-fcm-with-dependecy-updated": "^6.3.1", And there is no checking for permission at all... .requestPushPermissionIOS() doesn't exist and we do need this to allow the plugin to work for push notifications on apple?

I do see it in the src>iOS>FCMPlugin.d.ts - requestPushPermissionIOS(onSuccess?: () => void, onError?: (error: Error) => void): void;

however cannot use it in angular... And have imported it correctly since I can use .getToken() and the others...

I get this in angular ts :

Screenshot 2020-05-21 at 11 37 33

Is it perhaps not Ionic native that hasn't updated it.... Cause I don't see it in npm install @ionic-native/fcm

@ionicTeam..... These are the only options available on FCMPlugin.
Screenshot 2020-05-21 at 14 14 59

@danielsogl not sure if I address this to you but anyone who can help?

RichardBoyder commented 4 years ago

Hi guys. Not sure if this helps as well. But the owner of the fcm plugin has done a pull request into Ionic/native .... I think once Ionic team has accepted and we can install it via npm ... The requestPushPermissionIOS Will work.

@JuanJo-RC this should sort this threads issue.

simion commented 4 years ago

Until https://github.com/ionic-team/ionic-native/pull/3430 is merged, you can do this:

    const w: any = window;
    w.FCMPlugin.requestPushPermissionIOS(() => {
      console.log('push permissions recieved');
    }, (e) => {
      console.log('push permissions failed', e);
    });
iChristosK commented 3 years ago

Having the same issue.

iChristosK commented 3 years ago

Any updates on this?

iChristosK commented 3 years ago

Any solution or alternative plugin to use?

Vatsov commented 3 years ago

Having the same issue.

alitalaee commented 3 years ago

Having the same issue.

simion commented 3 years ago

Until #3430 is merged, you can do this:

    const w: any = window;
    w.FCMPlugin.requestPushPermissionIOS(() => {
      console.log('push permissions recieved');
    }, (e) => {
      console.log('push permissions failed', e);
    });

I've fixed this the proper way: dropped cordova and migrated https://clandesto.app to capacitor.
Rewrote most native integrations to capacitor equivalent, including firbase notifications: https://capacitorjs.com/docs/apis/push-notifications

github-actions[bot] commented 2 years ago

There has been no recent activity and this issue has been marked inactive.

ash737 commented 2 years ago

Until #3430 is merged, you can do this:

    const w: any = window;
    w.FCMPlugin.requestPushPermissionIOS(() => {
      console.log('push permissions recieved');
    }, (e) => {
      console.log('push permissions failed', e);
    });

Hi @simion, I face the same issue and I'm very new in ionic. Can I know where I add this code to slove the problem?