简体   繁体   中英

Is it possible to send with pushwoosh custom push-notification with certain parameters that are saved locally on the device

I'm developing in Titanium a cross platform app that runs on IOS and Android. To send my push notification I'm considering using Pushwoosh but I'm open for suggestion.

On the app certain parameters are saved locally that will effect the content of the push notification. Is it now possible to get these locally saved parameters to Pushwoosh so I can send custom notification and how would I do that?

Yes, it's called a payload.

Not sure how PushWoosh works with payloads... but you can use Parse.

When you receive the Push you get out of that the custom payload data (max size is 256 bytes and in iOS8+ it's 2 Kb of data) and save it into your App:

Ti.Network.registerForPushNotifications({
    types: [ Ti.Network.NOTIFICATION_TYPE_BADGE, Ti.Network.NOTIFICATION_TYPE_ALERT, Ti.Network.NOTIFICATION_TYPE_SOUND ],
    success: function(e) { Ti.App.Properties.setString('token', e.deviceToken); subscribePush();},
    error: function (e) { alert("error: " + JSON.stringify(e)); },
    callback: function (e) {
        alert('the push ' + JSON.stringify(e) ); // Works Only on RUN Device

        // Store your Data in the app
        Ti.App.Properties.setObject('myPushedData', e.data)
    }
});

It's definitely possible with Pushwoosh - you can pass any custom JSON data in a "key":"value" format along with your push notifications from both PW Control Panel and through API ( "data" parameter). In the resulting push payload this data is passed as a value of the "u" parameter.

Please refer to the code sample from Pushwoosh Titanium guide on how to access this additional custom data from the payload:

// Process incoming push notifications
    function receivePush(e) {
        alert('Received push: ' + JSON.stringify(e));
        Ti.API.warn("push message received: " + JSON.stringify(e));

            //send stats to Pushwoosh about push opened
            PushWoosh.sendPushStat(e.data.p);
            var pushwoohURL = e['data']['l'];

            var a = Ti.UI.createAlertDialog({
                title : 'New Message',
                message : e.data.alert,
                buttonNames : ['Open', 'Close']
                //message : JSON.stringify(e.data)  //if you want to access additional custom data in the payload
            });
            a.show();

            a.addEventListener('click', function(e) {
               if (e.index == 0) {
                Titanium.Platform.openURL(pushwoohURL);
               }
            });
    }

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