简体   繁体   中英

PhonegapPluginPush - getting "OK" as push data

We're trying to get data from a push when the application is killed.

Here a stack info:

Android: 8
device: Xiaomi Redmi 5
cordova: 7.1.0
cordova-android: 6.4.0
phonegap-plugin-push: 2.1.2

Registration and Handlers Set

user registers FCM token and exec. the following code. Finally

push.on('notification', (data) => { 
   .... statement_1
    callbackA(data); 
})

push.subscribe('notification', (data) => { 
   .... statement_2
   // This statement is called only if 
   //   app is closed and the user taps 
   //   onto notification in the shade 
})

We are registering and subscribing to on the same 'notification' event due to a problem with Android / App Closed. ( Normally, 'notification' event is not triggered if user tap on the notification when the app is killed -- see https://github.com/phonegap/phonegap-plugin-push/issues/2859 )

server push request example

{
  "registration_ids" : [ "...." ],
  "priority" : 5,
  "data" : {
    "title" : "Push with URL",
    "message" : "Questo invece è un esempio di push con un URL ",
    "purpose" : "NEWS",
    "id" : "2",
    "notId" : 5,
    "url" : "https://www.ciao.it/",
    "actions":[
         {
            "title":"Accept",
            "callback":"show",
            "foreground":true
         }
      ]
  }
}

Problem is that now, the event is triggered correctly, but plugin pass ad data 'OK' string instead push data for both statements (1-2).

What's wrong??

( FYI : Normal scenarios [background, foreground] are working like a charm! )

Super thanks in advance

We solve considering the ADB logcat.

In the app re-open process, it's clear that the listener was registered after the plugin's intent is processed.

So, as the first rows of the main ".run" module statement, we put the following code

$ionicPlatform.ready(function() {
    if (ionic.Platform.isAndroid()) {
      var push = PushNotification.init({
        android: {}
      });
      push.on("notification", function(data) {
        $$PushManager.init(data);
      });
    }
  });

With the above rows, we are able to treat push with the service in charge of that.

Simon

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM