Appcelerator and Urban Airship
I am trying out Urban Airship with Appcelerator but I am having problems with using it. This is my code in App.js:
Will it be "activated" when the user opens the app and then register automatically with Urban Airship?
UrbanAirship = require('ti.urbanAirship');
Ti.API.info("module is => "+UrbanAirship);
Ti.include('common/urbanairship.js');
UrbanAirshi开发者_JS百科p.key='XXX';
UrbanAirship.secret ='XXX';
UrbanAirship.master_secret='XXX';
UrbanAirship.baseurl = 'https://go.urbanairship.com';
Ti.Network.registerForPushNotifications({
types: [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
],
success:function(e){
var deviceToken = e.deviceToken;
Ti.API.info('successfully registered for apple device token with '+e.deviceToken);
var params = {
tags: ['version'+Ti.App.getVersion()],
alias: 'testing'
};
UrbanAirship.register(params, function(data) {
Ti.API.debug("registerUrban success: " + JSON.stringify(data));
}, function(errorregistration) {
Ti.API.warn("Couldn't register for Urban Airship");
});
},
error:function(e) {
Ti.API.warn("push notifications disabled: "+e);
},
callback:function(e) {
var a = Ti.UI.createAlertDialog({
title:'New Message',
message:e.data.alert
});
a.show();
}
});
The modules are always hit or miss for me.
Very rarely have they worked without a lot of troubleshooting.
I've gone the old-school route and it has worked fine for me - although I did change urbanairship.js
to add eventlisteners on windowfocus to the register/alias fields in the final app.
But for testing just leave as is. Hope this helps - http://wiki.appcelerator.org/display/guides/Push+Notifications
精彩评论