我正在使用离子框架开发一个移动应用程序。我已成功实现推送通知。我的设备上已成功通知。一切正常。现在我想在我的应用程序中访问标题。 这是我的代码:
$ionicUser.identify(user).then(function(){
//$scope.identified = true;
//alert('User ID ' + user.user_id);
//alert("here");
$ionicPush.register({
canShowAlert: true, //Can pushes show an alert on your screen?
canSetBadge: true, //Can pushes update app icon badges?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: true, //Can run actions outside the app,
onNotification: function(notification) {
alert(notification.title);//here I want to get title
// Handle new push notifications here
// console.log(notification);
return true;
我正在使用php发送通知: 这是代码:
$msg = array
(
'notId' => time(),
'message' => 'Technovault is awesome!!!',
'title' => 'Title',//get this title inside my app
'smallIcon' =>'icon',
//'path' =>'www.google.com'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . 'xxxxxxxxxx',
'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 );
echo $result;
}
Please help
答案 0 :(得分:0)
您可以从有效负载对象访问具有notification.payload.title
结构的标题,并且每个通知的参数foreground
都具有值false
或true
。当您通过单击通知来应用程序时,它将具有false
值,因此您可以使用它:
onNotification: function(notification) {
if(notification.foreground === false){
//put here your logic to go in any state
}
}