使用离子分析推送通知 [英] Parse push notification with ionic

查看:96
本文介绍了使用离子分析推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用parse设置推送通知来处理收到的通知。



我使用了 phonegap-parse-plugin 插件并且能够正确设置。



我的问题是我无法处理收到的通知。我想根据通知json params将用户重定向到通知页面。



所以,我决定切换到 parse-push-plugin ,但我的问题是我甚至无法显示警告注册框;它甚至找不到ParsePushPlugin方法。



我按照教程这很简单并将其添加到我的app.js文件中

  ParsePushPlugin.register(
{appId:xxx,clientKey:xxx,eventKey:myEventKey},//将触发receivePN [pnObj。 myEventKey]
function(){
alert('成功注册设备!');
},
函数(e){
alert('错误注册设备: '+ e);
});

ParsePushPlugin.on('receivePN',函数(pn){
alert('我得到此推送通知:'+ JSON.stringify(pn));
} );

警报成功无法显示,所以我猜它不起作用或我做得不对使用 phonegap-plugin-push 。它易于实现和使用。



配置:

  var push = PushNotification.init({
android:{
senderID:Your-sender-ID,
forceShow:true,//在屏幕上显示通知为以及
iconColor:#403782,
徽章:true,
clearBadge:true//清除应用徽章
},
ios:{
alert:true,
badge:true,
clearBadge:true,
声音:true,
forceShow:true
},
windows:{}
});

设备注册:

  push.on('registration',function(data){
localStorage.setItem('pushToken',data.registrationId); //保存注册ID
});

处理通知

  push.on('notification',function(data){
console.log(data);
//处理所有请求
if(data.additionalData。$ state ==mystate){
$ state.go('app.conversations');
}
})


I am trying to set up a push notification with parse to handle received notifications.

I used phonegap-parse-plugin plugin and was able to set it up correctly.

My problem with it is that I cannot handle the received notifications. I would like to redirect a user to a the page for the notification based on the notification json params.

So, I decided to switch to parse-push-plugin, but my problem with it is that I cannot even get it to show the alert registered box; it cannot even find the ParsePushPlugin method.

I followed the tutorial which is simple enough and added this to my app.js file

ParsePushPlugin.register(
    { appId:"xxx", clientKey:"xxx", eventKey:"myEventKey" }, //will trigger receivePN[pnObj.myEventKey]
    function() {
        alert('successfully registered device!');
    },
    function(e) {
        alert('error registering device: ' + e);
});

ParsePushPlugin.on('receivePN', function(pn){
    alert('yo i got this push notification:' + JSON.stringify(pn));
});

The alert success just failed to show so I guess it is not working or I am not doing the right thing.

解决方案

Use phonegap-plugin-push. It is easy to implement and use.

Config :

    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": {}
    });

Device Registration :

    push.on('registration', function(data) {
            localStorage.setItem('pushToken', data.registrationId); // Save registration ID
    });

Handle Notifications

    push.on('notification', function(data) {
        console.log(data);
        // Handle all requests here
        if (data.additionalData.$state == "mystate") {
            $state.go('app.conversations');
        }
    })

这篇关于使用离子分析推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆