我已经设置了一个处理推送通知的模块,其中包含:
//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);
};
场景:我在Controller中使用它,以便我可以传递与Controller相关的回调(例如,在回调处理之后我想关闭控制器/视图并打开另一个) :
//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.
}
问题是: cback 功能未被传递,或者,在 CloudPush-callback 事件被调用时, cback 不再存在了。 我得到了以下日志:
[myPush.js][setAppPushNotifications]: cback=function
[myPush.js][setAppPushNotifications]: cback=undefined
[myPush.js][getIncomingNotification]: cback=undefined
关于给定方案的解决方案是什么? 请告诉我一些代码。 感谢。
答案 0 :(得分:1)
尝试这个......
//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);
};