-1
我正在開發一個使用離子框架的移動應用程序。我已成功實現推送通知。通知成功地發佈在我的設備上。一切正常。現在我想在我的應用程序中訪問標題。 這裏是我的代碼:在離子推送通知中的應用程序內訪問標題
$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
你能在這裏貼的是執行console.log(通知)的'結果;'線和以什麼方式你想使用這個標題? –
我只收到我用我的php腳本發送的消息 –
嘗試console.log(notification.payload.title)並查看它顯示的內容。 –