Start a new topic

Using urban airship module with Titanium

Just a quick clarification





Is it possible to use the module from appcelerator with Titanium and the credentials provided by Kinvey? Or are they differ in any way to "normal" keys, if i create a new account directly on Urban Airship?



Addition:

Is it possible to use the analytic tools from Urban Airship with my "only" kinvey Account? Like registered devices and so on - if not, is this a planned feature? (I think it's very interesting for statistics and development)



Best,

Nico






Hi Nico, To answer your first question- yes, you can use the Titanium module.



We have no plans to integrate with the Urban Airship analytics tools currently, but I'll pitch it to the team and see what they think.
Thanks for your response!



Than i'll try to setup the module/push again and search for the error.
Hey,



after a lot of trying - i hope you can help:





1. I've setup the Push-Settings in the Kinvey-Backend using my push-certificate (development).

2. Paste the credentials to the plist file inside my Titanium-Project. (So the Urban Airship module can acces them)

3. Using this Code:



function initPush() {

console.log("Init Push");



UrbanAirship.tags = [ 'testingtesting', 'appcelerator', 'my-tags' ];

UrbanAirship.alias = 'testDevice';

UrbanAirship.autoBadge = true;

UrbanAirship.autoResetBadge = true;







Titanium.Network.registerForPushNotifications({

types:[

Ti.Network.NOTIFICATION_TYPE_BADGE,

Ti.Network.NOTIFICATION_TYPE_ALERT,

Ti.Network.NOTIFICATION_TYPE_SOUND

],

success: eventSuccess,

error: eventError,

callback: eventCallback

});

}





function eventCallback(e){

alert(e);

UrbanAirship.handleNotification(e.data);



alert(' Message: ' + e.data.alert);

alert(' Payload: ' + e.data.aps);

}



function eventSuccess(e) {

// *MUST* pass the received token to the module

UrbanAirship.registerDevice(e.deviceToken);



alert('Received device token: ' + e.deviceToken);

// labelID.text = e.deviceToken;

// btnOpen.enabled = true;

}



function eventError(e) {

//alert('Error:' + e.error);

var alert = Ti.UI.createAlertDialog({

title: 'Error',

message: e.error

});

alert.show();

}







Than i am publishing the application to my iphone using my developer certificate (not distribution). The device-token is requested correctly. But if i am sending a push over the Kinvey-Console nothing happen in the application.





Any Idea? (Or even an idea how to debug this stuff? Not sure how to "search" for the error)



best, Nico
You also need to register the device token with a Kinvey user. This can be done by calling the register endpoint manually, see [here](http://devcenter.kinvey.com/titanium/guides/push#Registeringadevice).
Hmmm at wich place in the code You enter that?



As soon as i get the devicetoken?



I've tried that - same (not working) result.
Yes, right after `UrbanAirship.registerDevice(e.deviceToken);`. Can you show me the full code including the snippet where you register the device with Kinvey?
Hey of course:





`function initPush() {

console.log("Init Push");

UrbanAirship.tags = [ 'testingtesting', 'appcelerator', 'my-tags' ];

UrbanAirship.alias = 'testDevice';

UrbanAirship.autoBadge = true;

UrbanAirship.autoResetBadge = true;

Titanium.Network.registerForPushNotifications({

types:[

Ti.Network.NOTIFICATION_TYPE_BADGE,

Ti.Network.NOTIFICATION_TYPE_ALERT,

Ti.Network.NOTIFICATION_TYPE_SOUND

],

success: eventSuccess,

error: eventError,

callback: eventCallback

});

}

function registerDeviceOnKinveyUser(token) {



request.open('POST', Kinvey.API_ENDPOINT + '/push/kid_PTYnZFBS09/register-device');

request.onerror = function(e) {

alert(JSON.stringify(e));

};

request.onload = function(e) {

alert(JSON.stringify(e));

};

request.setRequestHeader('Authorization', 'Kinvey ' + Kinvey.getActiveUser()._kmd.authtoken);

request.setRequestHeader('Content-Type', 'application/json');

request.send({

'platform' : 'ios',

'deviceId' : token

});

}

function eventCallback(e){

alert(e);

UrbanAirship.handleNotification(e.data);



alert(' Message: ' + e.data.alert);

alert(' Payload: ' + e.data.aps);

}

function eventSuccess(e) {

// *MUST* pass the received token to the module

UrbanAirship.registerDevice(e.deviceToken);



alert('Received device token: ' + e.deviceToken);



registerDeviceOnKinveyUser(e.deviceToken);

// labelID.text = e.deviceToken;

// btnOpen.enabled = true;

}

function eventError(e) {

var alert = Ti.UI.createAlertDialog({

title: 'Error',

message: e.error

});

alert.show();

}

`





That's my testcase - Just to make a quick test if the push messages send from kinvey are received in the application. - so far it did not.





Thanks for help,

Nico



Looking at our logs, it doesn’t seem the call to register with Kinvey was ever made - no user seems to have a push token. Do you actually get the `Received device token:` alert? And can you see what the `request.onload` in the `registerDeviceOnKinveyUser` method alerts?
I don't really know why - but now it's working ... :smile:



To check if the user already is enabled for receiving pushmessages, using the push attribute of the user object is the best way, i guess?

Yes, the `_push` attribute on the user will contain its device token(s).
Login or Signup to post a comment