ionic-framework - 在后台收到的通知不会触发 pushObject.on('notification')。当应用程序也被关闭时
问题描述
我使用 php 向 ionic 应用程序发送通知,pushObject.on('notification') 仅在应用程序运行时执行,但当应用程序处于后台或关闭时,单击通知仅打开应用程序和我的 pushObject.on( '通知')。不叫。
我已经制作了很多有效负载版本,如解决方案 phonegap-plugin-push on("notification") event is not fire 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)
前台执行,如果应用程序在后台或已关闭,请单击通知仅打开应用程序。
解决方案
推荐阅读
- java - JAVA中数组中值重复的百分比频率
- google-apps-script - Google Script custom function to return rich text
- python - ValueError: 'c' argument has 2 elements which is not acceptable for use, when trying python matplotlib scatterplot
- regex - RegEx for taking product# and Order#
- python - 程序关闭时的 SQL Alchemy 不一致错误
- python-3.x - 如何在 Python 中忽略文本文件中某行的某些部分?
- c - 在动态内存的情况下如何处理二维数组,即在编译时未定义元素的数量
- c - 如何更改 uint32_t 变量中单个字节的值?
- azure-search-.net-sdk - Microsoft.Azure.Search API - ContnueSearchAsync - 是否附加了结果?
- php - 如何在sql中检索当年有记录的月份名称列表?