I am developing a mobile app using ionic framework.I have successfully implement push notification.Notifications are successfully coming on my device.Everything works perfectly. Now i want to access title inside my application. Here is my code:
$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;
I am using php for send notification: here is code:
$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
You can access title from payload object which have strucuture like notification.payload.title
, and every notification has parameter foreground
having value false
or true
. When you come to application by clicking on notification then it will have false
value, so you use this like:
onNotification: function(notification) {
if(notification.foreground === false){
//put here your logic to go in any state
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.