【发布时间】:2015-08-30 21:15:18
【问题描述】:
我正在使用离子框架开发移动应用程序。我已成功实现推送通知。当我点击通知时,我希望它应该进入特定页面。我将如何做到这一点? 在客户端:
var user = $ionicUser.get();
if(!user.user_id) {
// Set your user_id here, or generate a random one.
user.user_id = $ionicUser.generateGUID();
};
// Identify your user with the Ionic User Service
$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) {
// Handle new push notifications here
// console.log(notification);
return true;
}
});
});
});
})
.config(['$ionicAppProvider', function($ionicAppProvider) {
$ionicAppProvider.identify({
app_id: 'xxxxxxxxxxxxx',
api_key: 'xxxxxxxxxxxxxx',
dev_push: false
});
}])
在服务器端我使用了 php:
$deviceToken = 'APA91bHKwBKrIjmmZ9lke97fl_GbOQ9iRRo-S2sNnZp085hPqVaTHMOd0wqhYFF1PtrtOzFrETX7ZNIkU0JDhC49Tby_AEFIQFRX99B0QpZd7xdiTqsP6sZ08P-8ESdJAie5AJNxhW89nQ7S9evZNcAc9tsJaG91Xw';
$registrationIds = explode(",",$deviceToken);
//$registrationIds = array($deviceToken);
// prep the bundle
$msg = array
(
'notId' => time(),
'message' => 'Technovault is awesome!!!',
'title' => 'Title',
'smallIcon' =>'icon'
);
$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;
}
else {
echo "Error";
}
【问题讨论】:
-
请用您的代码更新您的问题。