titanium - ACS Appcelerator iOS not receiving push -
i'm trying make push notification working dev/production environment through appcelerator platform. created push certificates (dev/prod) on apple developer platform, exported .p12 file, , uploaded on arrowdb ios push configuration. titanium app , arrowdb seems correctly linked (good keys production , developpement).
from app, device token, successfull return subscribing notifications, , can see appcelerator have 1 ios device linked.
when send push notification appcelerator arrowdb platform, don't receive while appcelerator logs shows successful push.
my code acs notification handling :
var cloud = require('ti.cloud'); var android = ti.platform.name === 'android'; var ios = !android && (ti.platform.name === 'iphone os'); var blackberry = !android && !ios && (ti.platform.name === 'blackberry'); cloud.debug = true; // optional; if add line, set false production var devicetoken = null; // check if device running ios 8 or later if (ti.platform.name == "iphone os" && parseint(ti.platform.version.split(".")[0]) >= 8) { // wait user settings registered before registering push notifications ti.app.ios.addeventlistener('usernotificationsettings', function registerforpush() { // remove event listener once registered push notifications ti.app.ios.removeeventlistener('usernotificationsettings', registerforpush); ti.network.registerforpushnotifications({ success: devicetokensuccess, error: devicetokenerror, callback: receivepush }); }); // register notification types use ti.app.ios.registerusernotificationsettings({ types: [ ti.app.ios.user_notification_type_alert, ti.app.ios.user_notification_type_sound, ti.app.ios.user_notification_type_badge ] }); } // ios 7 , earlier else { ti.network.registerforpushnotifications({ // specifies notifications receive types: [ ti.network.notification_type_badge, ti.network.notification_type_alert, ti.network.notification_type_sound ], success: devicetokensuccess, error: devicetokenerror, callback: receivepush }); } // process incoming push notifications function receivepush(e) { console.log('received push: ' + json.stringify(e)); alert('received push: ' + json.stringify(e)); } // save device token subsequent api calls function devicetokensuccess(e) { devicetoken = e.devicetoken; } function devicetokenerror(e) { alert('failed register push notifications! ' + e.error); } function acspush(acsuid, acspwd) { this.acsuid = acsuid || false; this.acspwd = acspwd || false; } acspush.prototype.registerdevice = function(channel_name, onreceive, onlaunched, onfocused, androidoptions, iosoptions, blackberryoptions) { var = this, token = ''; function devicetokensuccess(e) { console.log('device token: ' + e.devicetoken); token = e.devicetoken; that.token = token; logintoacs(that.acsuid, that.acspwd, token, channel_name); } function devicetokenerror(e) { console.log('token error: ' + e.error); } function receivepush(e) { onreceive(e.data); console.log("push notification received: " + json.stringify(e.data)); } if (android) { var cloudpush = require('ti.cloudpush'); cloudpush.retrievedevicetoken({ success : devicetokensuccess, error : devicetokenerror }); cloudpush.focusapponpush = androidoptions.focusapponpush || false; cloudpush.showappontrayclick = androidoptions.showappontrayclick || false; cloudpush.showtraynotification = androidoptions.showtraynotification || false; cloudpush.showtraynotificationswhenfocused = androidoptions.showtraynotificationswhenfocused || false; cloudpush.singlecallback = androidoptions.singlecallback || true; cloudpush.addeventlistener('callback', onreceive); cloudpush.addeventlistener('trayclicklaunchedapp', onlaunched); cloudpush.addeventlistener('trayclickfocusedapp', onfocused); } else if (ios) { // check if device running ios 8 or later if (parseint(ti.platform.version.split(".")[0]) >= 8) { function registerforpush() { ti.network.registerforpushnotifications({ success : devicetokensuccess, error : devicetokenerror, callback : receivepush }); // remove event listener once registered push notifications ti.app.ios.removeeventlistener('usernotificationsettings', registerforpush); }; // wait user settings registered before registering push notifications ti.app.ios.addeventlistener('usernotificationsettings', registerforpush); // register notification types use ti.app.ios.registerusernotificationsettings({ types : iosoptions.types, categories : iosoptions.categories }); } else { // ios 7 , earlier ti.network.registerforpushnotifications({ // specifies notifications receive types : iosoptions.types, success : devicetokensuccess, error : devicetokenerror, callback : receivepush }); } } else if (blackberry) { ti.blackberry.createpushservice({ appid : blackberryoptions.appid, ppgurl : blackberryoptions.ppgurl, usepublicppg : blackberryoptions.usepublicppg, launchapplicationonpush : blackberryoptions.launchapplicationonpush, onsessioncreated : function(e) { console.log('session created'); }, onchannelcreated : function(e) { console.log('channel created\nmessage: ' + e.message + '\ntoken: ' + e.token); token = e.token; that.token = token; console.log("device token: " + token); logintoacs(that.acsuid, that.acspwd, token, channel_name); }, onpushreceived : function(e) { onreceive(e.data); e.source.removeallpushes(); }, onconfigerror : function(e) { console.log('error\ntitle: ' + e.errortitle + +'\nmsg: ' + e.errormessage); }, onerror : function(e) { console.log('error\ntitle: ' + e.errortitle + +'\nmsg: ' + e.errormessage); }, onappopened : function(e) { onlaunched(e.data); e.source.removepush(e.pushid); } }); } else { alert("push notification not implemented yet acspushmod " + ti.platform.osname); } }; acspush.prototype.unsubscribefromchannel = function(channel_name, token, onsuccess, onfail) { var = this; cloud.pushnotifications.unsubscribe({ channel : channel_name, device_token : token }, function(e) { if (e.success) { onsuccess(e); } else { onfail(e); } }); }; acspush.prototype.gettoken = function() { return this.token; }; function logintoacs(acsuid, acspwd, token, channel_name) { if (!acsuid && !acspwd) { console.log("logintoacs -> subscribe guest"); subscribeforpushnotifications(token, channel_name, true); return; } cloud.users.login({ login : acsuid, password : acspwd }, function(e) { if (e.success) { var user = e.users[0]; console.log("logintoacs -> status: successful"); subscribeforpushnotifications(token, channel_name); } else { console.log('acsuid = ' + acsuid + " acspwd = " + acspwd); console.log("logintoacs -> error :" + e.message); } }); }; function subscribeforpushnotifications(token, channel_name, subscribeasguest) { var prams = { channel : channel_name, type : ios ? 'ios' : ti.platform.osname, // osname return iphone / ipad on ios device_token : token }; var callback = function(e) { if (e.success) { console.log('subscribeforpushnotifications -> status: successful [' + channel_name + ']'); } else { console.log('subscribeforpushnotifications -> error ' + token + '(subscribetoserverpush) :\\n' + ((e.error && e.message) || json.stringify(e))); } }; if (subscribeasguest) { cloud.pushnotifications.subscribetoken(prams, callback); } else { cloud.pushnotifications.subscribe(prams, callback); } };
and code used work before change appcelerator account (migrating client account).
if guys have idea of doing wrong, thankful.
thanks lot !
environment : appcelerator studio, titanium sdk 5.0.0.ga, iphone5s
Comments
Post a Comment