Question

I have set up a module for dealing with Push-Notifications which has this:

//myPush module
var CloudPush = require('ti.cloudpush'); 
...
        var setAppPushNotifications = function(cback) {
            // Process incoming push notifications
            log('cback=' + typeof cback);  //log is a wrapper to Ti.API.info
            CloudPush.addEventListener('callback', function (evt,cback) {
                log('Inside CloudPush-Callback.');
                log('cback=' + typeof cback); 
                getIncomingNotification(evt, cback);
            });
        };
        var getIncomingNotification = function(evt,cback) {
            //return if zero payload 
            //test for app required basic fields
            log('cback=' + typeof cback); 
            cback(evt.payload);
        }; 

Scenario: I use it inside a Controller, so that I can pass a callback that is Controller related (for example, after callback processing I want to close the controller/views and open another one):

//controller code
var myPush = Alloy.Globals.myPush; 
...
    myPush.setAppPushNotifications(processNotificationPayload);

    function processNotificationPayload(p) {
        //select notification channel
        //do some processing...
        //close controller and view and get back to index.
    }

The problem is: cback function is not been passed along, or, by the time of CloudPush-callback event is called, cback doesn't exists anymore. I got the following logs:

[myPush.js][setAppPushNotifications]: cback=function
[myPush.js][setAppPushNotifications]: cback=undefined
[myPush.js][getIncomingNotification]: cback=undefined

What would be a solution respecting the given scenario ? Please show me some code. Thanks.

Was it helpful?

Solution

try this one....

//myPush module
var CloudPush = require('ti.cloudpush'); 
...
        var setAppPushNotifications = function(cback) {
            // Process incoming push notifications
            log('cback=' + typeof cback);  //log is a wrapper to Ti.API.info
            CloudPush.addEventListener('callback', function (evt) {
                log('Inside CloudPush-Callback.');
                log('cback=' + typeof cback); 
                getIncomingNotification(evt,cback);
            });
        };
        var getIncomingNotification = function(evt,cback) {
            //return if zero payload 
            //test for app required basic fields
            log('cback=' + typeof cback); 
            cback(evt.payload);
        }; 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top