如何使用内置的Ionic Framework在Android混合应用程序中发送推送通知。
我是新手,请指导我一步一步如何发送离子推送通知?
我在youtube和其他网站上看到了不同的教程,但我很困惑在哪里添加这些网站上显示的代码。我有GCM项目编号(SENDER_ID
),但不知道放在哪里。
请详细说明。
提前致谢。
答案 0 :(得分:0)
尝试使用phonegap-plugin-push?它易于实现和使用。
配置:
var push = PushNotification.init({
"android": {
"senderID": "Your-sender-ID",
"forceShow": true, // To show notifications on screen as well
"iconColor": "#403782",
"badge": "true",
"clearBadge": "true" // To clear app badge
},
"ios": {
"alert": "true",
"badge": "true",
"clearBadge": "true",
"sound": "true",
"forceShow": "true"
},
"windows": {}
});
设备注册:
push.on('registration', function(data) {
localStorage.setItem('pushToken', data.registrationId); // Save registration ID
});
处理通知
push.on('notification', function(data) {
console.log(data);
// Handle all requests here
if (data.additionalData.$state == "mystate") {
$state.go('app.conversations');
}
})