[英]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
其值为false
或true
。 当您通过单击通知进入应用程序时,它将具有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.