Php 如果应用程序关闭,推送通知不会出现
我正在android中使用PHP(使用fcm)处理推送通知,推送通知工作正常,但每当我的应用程序“关闭”时,我不会收到任何推送通知(只有当我的应用程序“打开”时,我才会收到通知) 这是我的密码,哪里错了Php 如果应用程序关闭,推送通知不会出现,php,android,firebase,push-notification,Php,Android,Firebase,Push Notification,我正在android中使用PHP(使用fcm)处理推送通知,推送通知工作正常,但每当我的应用程序“关闭”时,我不会收到任何推送通知(只有当我的应用程序“打开”时,我才会收到通知) 这是我的密码,哪里错了 function testingPush(){ define("FCM_URL", "https://fcm.googleapis.com/fcm/send"); define( "FCM_KEY","xxx
function testingPush(){
define("FCM_URL", "https://fcm.googleapis.com/fcm/send");
define( "FCM_KEY","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$devicetype1 = "ios";
$devicetype2 = "android";
$deviceType = $rows['device_type']; // coming from database
$deviceToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$titleMessage="Push Notification Testing";
$message="Lorem Ipsum";
$msgs = array();
if (strcasecmp($devicetype1, $deviceType) == 0)
{
/* sending push to IOS */
$notification = array('body'=>$message,
'sound'=>"default",
'title'=>$titleMessage,
'badge'=>1);
$data = array('notificationType'=>1,
'displayURL'=>"https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG");
$msgs = array('to'=>$deviceToken,
'content_available'=>true,
'mutable_content'=>true,
'notification'=>$notification,
'priority'=>'high',
'data'=>$data);
}
else{
/* sening push to android */
$notification = array('contentTitle'=>$titleMessage,
'message'=>$message);
$msgs = array('to'=>$deviceToken,
'priority'=>'high',
'data'=>$notification);
}
$this->sendPushNotification_With($msgs);
}
private function sendPushNotification_With($json) {
$headers = array('Authorization: key=' . FCM_KEY,'Content-Type: application/json');
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, FCM_URL );
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($json) );
$result = curl_exec($ch );
curl_close( $ch );
}
我认为问题在于
$notification
中的contentTitle,将其替换为title
,它应该可以工作,而且在您的ios通知中,您使用notification
作为单独的变量,我建议您在数据中传递通知参数,由于通知在后台不起作用。如果上述操作不起作用,请重新检查您的密钥我认为问题在于$notification
中的contentTitle,将其替换为title
,它应该起作用,并且在ios通知中,您使用notification
作为单独变量,我建议您在数据中传递通知参数,因为通知在后台不起作用。如果上述操作不起作用,请重新检查您的密钥这将有助于您确定在设置中未阻止应用程序通知这将有助于您确定在设置中未阻止应用程序通知