Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse push notification with ionic

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.

like image 229
Uchenna Avatar asked Apr 21 '15 11:04

Uchenna


1 Answers

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');
        }
    })
like image 149
Sangwin Gawande Avatar answered Nov 02 '22 21:11

Sangwin Gawande