Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

push-notification and push-receive not fired when a push notification is received #331

Closed ronaldalfaro closed 4 years ago

ronaldalfaro commented 4 years ago

Plugin version pushwoosh-cordova-plugin 7.18.8 "Pushwoosh"

Ionic:

Ionic CLI : 6.1.0 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : ionic-angular 3.9.8 @ionic/app-scripts : 3.2.4

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1) Cordova Platforms : android 8.1.0, ios 5.1.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.3, (and 15 other plugins)

Utility:

cordova-res : 0.9.0 native-run : not installed

System:

Android SDK Tools : 26.1.1 (/Users/ronaldalfaro/Library/Android/sdk) ios-deploy : 1.10.0 ios-sim : 8.0.2 NodeJS : v13.7.0 (/usr/local/Cellar/node/13.7.0/bin/node) npm : 6.13.6 OS : macOS Mojave Xcode : Xcode 11.3.1 Build version 11C504

I have followed all steps as documentation, but seems push-notification and push-receive are not firing when a push notification is received, in console I can see a log like this:

willPresentNotification: { aps = { alert = "Prueba 5!!!"; sound = default; }; md = { uid = 8784352030; "user_id" = 88000; }; messageType = notification; p = "!"; } 2020-02-12 14:37:16.641397-0600 App[779:201445] willPresentNotification: foreground notification not set

wfhm commented 4 years ago

@ronaldalfaro,

This is something our SDK is not expected to print in the console. May I ask you to share your Pushwoosh integration code?

ronaldalfaro commented 4 years ago

Sure! tell me if you need something else...

initPushwoosh is in constructor: constructor( platform: Platform, private loadingCtrl: LoadingController, statusBar: StatusBar, splashScreen: SplashScreen, private appRate: AppRate, private alertCtrl: AlertController, ) { platform.ready().then(() => { initPushwoosh()

.....................etc.....

This is initPushwoosh function:

initPushwoosh() { var pushNotification = (window).plugins.pushNotification;

    //set push notifications handler, is used to react on a notification click event, 
    //which requires user interaction, e.g. to navigate within your app, trigger a new process in your app etc.
      document.addEventListener('push-notification',

        function(event) {
          var message = (<any>event).notification.message;
          var userData = (<any>event).notification.userdata;

          //alert("Push message opened: " + message);
          this.pushAlert(message);
          console.info(JSON.stringify((<any>event).notification));

          //dump custom data to the console if it exists
          if (typeof(userData) != "undefined") {
            console.warn('user data: ' + JSON.stringify(userData));
          }
        }
      );

      //When a push is received in foreground, the plugin fires push-receive automatically, 
      //and creates a notification in the Notification Center. When this notification is opened, 
      //it fires push-notification.
      document.addEventListener('push-receive',
        function (event) {
            var message = (<any>event).notification.message;
            var userData = (<any>event).notification.userdata;

            //alert("Push message received: " + message);
            this.pushAlert(message);
            console.info(JSON.stringify((<any>event).notification));

            //dump custom data to the console if it exists
            if (typeof (userData) != "undefined") {
              console.warn('user data: ' + JSON.stringify(userData));
            }
          }
       );

      //initialize Pushwoosh with projectid: "YOUR_FCM_SENDER_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.

      pushNotification.onDeviceReady({
        projectid: "xxxxxxxxxx",
        appid: "xxxxxxxxx",
        serviceName: ""
      });

      //register for push notifications
      var app = this;
      pushNotification.registerDevice(
        function(status) {
          //alert("registered with token: " + status.pushToken);
          console.log(JSON.stringify(['success register ', status]));
        },
        function(status) {
          //alert("failed to register: " + status);
          console.warn(JSON.stringify(['failed to register ', status]));
        }
      );
}

Device registration to Pushwoosh is working properly but when I receive a notification in foreground "push-receive" is not fired same case when I click a notification in iOS Notification Center "push-notification" is not working...

ronaldalfaro commented 4 years ago

Any idea? thanks...

wfhm commented 4 years ago

@ronaldalfaro,

May I ask you to create a support ticket at https://help.pushwoosh.com/hc/en-us/requests/new and share a reproducer IPA? Also, could you please share your config.xml and package.json?

CodeWithOz commented 4 years ago

Hi @wfhm @ronaldalfaro any updates on this? I can't know if the discussion was moved to the support ticket and/or if there's been a resolution. I don't have the problem yet (I'm still on version 7.18.4) but I'm considering upgrading to 7.18.8 so I'm just trying to do a bit of research into potential problems I may encounter. Thanks!

guv3n commented 4 years ago

Same here @wfhm @ronaldalfaro 'push-notification' and 'push-receive' callbacks are not fired on Android. It used to work well. I can't find what changes since. I also tried to update to latest plugin version but callbacks are still not fired. Did you find something interesting ?

edit : I'd like to add that the iOS version still works

ronaldalfaro commented 4 years ago

I didn't find anything :/ I will try again if there is a new version.

On Fri, Mar 27, 2020 at 4:21 AM Güven Urganci notifications@github.com wrote:

Same here @wfhm https://github.com/wfhm @ronaldalfaro https://github.com/ronaldalfaro 'push-notification' and 'push-receive' callbacks are not fired on Android. It used to work well. I can't find what changes since. I also tried to update to latest plugin version but callbacks are still not fired. Did you find something interesting ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/331#issuecomment-604923355, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4Y3NZWN5CZJB2WOMF3ZHTRJR43ZANCNFSM4KUEAC2Q .

guv3n commented 4 years ago

Did you open a ticket with pushwoosh's support ? The plugin used to work well. Maybe something changed on the Android's side ?

ronaldalfaro commented 4 years ago

No yet Guven, I just was playing with plugin and get the problem

On Fri, Mar 27, 2020 at 8:05 AM Güven Urganci notifications@github.com wrote:

Did you open a ticket with pushwoosh's support ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/331#issuecomment-605018968, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4Y3N7KI6I62XMLEXDQCRLRJSXELANCNFSM4KUEAC2Q .

guv3n commented 3 years ago

We found the problem ! props to @dmedyk It's related to this issue on cordova-android: edit-config on AndroidManifest.xml overwrite existing plugin configs

To edit the AndroidManifest, we had this line:

<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">

And it overwrote the Pushwoosh plugin settings.

There are 4 lines in https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/blob/f84b2a873a888b62479104d10aaccaba2cdac616/plugin.xml#L31

<meta-data android:name="com.pushwoosh.log_level" android:value="$LOG_LEVEL" />
<meta-data android:name="com.pushwoosh.foreground_push" android:value="$ANDROID_FOREGROUND_PUSH" />
<meta-data android:name="com.pushwoosh.notification_service_extension" android:value="com.pushwoosh.plugin.pushnotifications.PushwooshNotificationServiceExtension" />
<meta-data android:name="com.pushwoosh.internal.plugin_provider"    android:value="com.pushwoosh.plugin.internal.PhonegapPluginProvider" />

This config was overwritten by config.xml.

To fix it, we changed the path of file attribute to: <edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application" mode="merge">

Now, the events are fired in the Javascript.

I believe that it was introduced in Cordova 8.1

I also believe that if Pushwoosh update its plugin in a similar way to this one it should prevent the problem to occur to other developers

ping @wfhm