应用关闭时,我没有收到推送通知。 但是,当应用程序处于后台/前台时,它可以正常工作。
以下是app.component.ts中代码的一部分
initPushNotification()
{
// to initialize push notifications
const options: PushOptions = {
android: {
icon: 'small-icon',
forceShow: true
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
//Notification Display Section
alert(JSON.stringify(notification));
});
pushObject.on('registration').subscribe((registration: any) => {
alert(registration.registrationId);
});
pushObject.on('error').subscribe(error => {
alert('Error with Push plugin' + error);
});
}
这是我发送推送通知的PHP代码
<?php
public function androidNotification($title, $message, $registrationIds, $addData) {
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'accesskeyhere' );
// prep the bundle
$msg = array
(
'message' => $message,
'title' => $title,
'addData' => $addData,
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/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 );
curl_close( $ch );
}
这是什么问题?我正在使用离子平台。
我正在寻找论坛,但没有运气。我没有找到任何解决方案。