简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM