Php 在ionic推送通知中访问应用程序内部的标题

Php 在ionic推送通知中访问应用程序内部的标题,php,android,angularjs,ionic,Php,Android,Angularjs,Ionic,我正在使用ionic framework开发一个移动应用程序。我已经成功地实现了推送通知。通知已成功地发送到我的设备上。一切都很正常。现在我想访问我的应用程序中的标题。 这是我的密码: $ionicUser.identify(user).then(function(){ //$scope.identified = true; //alert('User ID ' + user.user_id); //alert("here"); $ionicPush.r

我正在使用ionic framework开发一个移动应用程序。我已经成功地实现了推送通知。通知已成功地发送到我的设备上。一切都很正常。现在我想访问我的应用程序中的标题。 这是我的密码:

 $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

您可以从负载对象访问标题,该对象的结构类似于
notification.payload.title
,并且每个通知都有参数
前台
的值
false
true
。当您通过单击通知来访问应用程序时,它将具有
false
值,因此您可以这样使用:

onNotification: function(notification) {
  if(notification.foreground === false){
    //put here your logic to go in any state
  }
}

你能在这里粘贴
console.log(通知)的结果吗行以及您希望以何种方式使用此标题?我只收到我用php scripttry console.log(notification.payload.title)发送的消息,并查看它显示的内容。现在我希望当我单击通知时,它将进入特定状态。谢谢…..问题已解决