在后台收到的通知不会触发pushObject.on('notification')。当应用程序也被选中时

时间:2019-05-28 02:04:56

标签: ionic-framework phonegap-pushplugin

我使用php将通知发送到ionic应用程序,仅在应用程序运行时执行pushObject.on('notification'),但当应用程序处于后台或关闭状态时,单击通知仅打开应用程序,而我的pushObject .on('notification')。不被调用。

与解决方案中的搜索一样,我已经制作了很多有效负载版本 phonegap-plugin-push on("notification") event is not firing when app is in background

我的php代码是

<?php
#API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xxxxxxx' );
#prep the bundle
$msg = array
(
    "notId"=> "test",
    "body"=> "test",
    "title"=> "Cabinet sahli : قرار جديد",
    "vibrate"=> 1,
    "sound"=>"default",
    "case_number"=> "test",
    "case_title"=>"test",
    "case_id"=> 13,
    "content-available"=> 1,
    "priority"=> "high",
    "additionalData"=>  [
        "surveyID" =>  "ewtawgreg-gragrag-rgarhthgbad",
    ]

);
$fields = array
(

//'registration_ids' => array('d7pT_z1pwYo:APA91bFK2KilUzZon1g4Yu5-bZgaqxeepcP0Owzn2a6QgGuK4HUsI-hQhRbAYANIYfl3xdDYq-k6lAsnNSFyRB4qgEH1wJqDRw6V4s3kKpg_OZHT4UZATZDo6hceZYiwzBS6eSXUfjYh'),
'registration_ids' => array('d1WrqmdONL0:APA91bFRlokdsFFOXygqnRaSuWwD7QnJIhFGoZj1wPGuWzSxFxkaEca4FPDsPxpDp1FmpZSQ6lCoTsepH2PP9KbJ7HbEGQBhT0ofx8gMbr9P-JPL8eZlff4rkY7uS3CWXAzmg0KkbChK'),
'data'  => $msg,
);


$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);

#Send Reponse To FireBase Server
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
echo $result;
curl_close( $ch );

我的离子代码是

 pushObject.on('notification').subscribe((notification: any) => {

          let json = JSON.parse(JSON.stringify(notification.additionalData));

          console.log(json);

          this.storage.set('notifs',json);
         console.log( this.storage.get('notifs'));

          if (notification.additionalData.foreground) {
              console.log('i got fired foreground');

              let youralert = this.alertCtrl.create({
                  title: 'Nouvelle audience',
                  message: notification.message,
                  buttons: [
                      {
                          text: "تخطي التنبيه",

                      },
                      {
                          text: "التفاصيل",
                          handler: () => {
                              this.nav.push(CasedetailPage,{id:json.case_id,titre:json.case_title,numero:json.case_number});
                          }

                      }]
              });
              youralert.present();

          }

          else if(notification.additionalData.background) {
              this.nav.push(CasedetailPage,{id:json.case_id,titre:json.case_title,numero:json.case_number});

              console.log('back');

          }

      });

该应用现在正在运行,并且将 if (notification.additionalData.foreground) 被谴责 并且如果该应用程序处于后台或关闭状态,则单击通知仅打开该应用程序。

0 个答案:

没有答案