当应用程序打开时:推送通知正常
当应用程序在后台时:推送通知振动和声音,但不显示在通知栏上
关闭应用程序时:未收到通知
这是我的推送通知初始化
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);
});
}
这是我的后端发件人:
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'accesskeyhere' );
// device ids
$registrationIds = array('mydeviceidhere');
// prep the bundle
$msg = array
(
'message' => "This is a Test Notification",
'title' => "This is a Test Title",
'addData' => "This is Test Additional Data",
'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 );
我做错了什么?或者我的代码中缺少某些内容?
如何使用离子2在应用程序关闭/在后台唤醒GCM服务?这里有人以前有同样的问题并已修复吗?请分享您的答案。谢谢
尝试使用选项
content-available: 1
见 https://github.com/phonegap/phonegap-plugin-push/issues/93
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#use-of-content_available-true