Parse push notification with ionic

折月煮酒 提交于 2019-12-03 17:48:15

问题


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.


回答1:


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');
        }
    })


来源:https://stackoverflow.com/questions/29771478/parse-push-notification-with-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!