簡體   English   中英

在離子推送通知中訪問應用程序內部的標題

[英]Access title inside application in ionic push notification

我正在使用離子框架開發移動應用程序。我已成功實現推送通知。通知已成功發送到我的設備上。一切正常。 現在我想訪問我的應用程序中的標題。 這是我的代碼:

 $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有效負載對象訪問標題,並且每個通知都有參數foreground其值為falsetrue 當您通過單擊通知進入應用程序時,它將具有false值,因此您可以像這樣使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM