I keep getting an error when trying to register for C2DM notifications on the device...
Error: Uncaught Type Error: Object # has no method 'register'
I successfully compiled the module using 1.8.2 and it loads but when I try to do:
var senderId = 'email@domain.com';
// the module is loaded earlier in the app under 'namespace.c2dm'
Ti.API.info("module is => " + namespace.c2dm);
Ti.API.info('Registering...');
namespace.c2dm.register(senderId, {
success:function(e)
{
Ti.API.info('JS registration success event: ' + e.registrationId);
Ti.API.info('Requesting: '+peak.config.rest_server+'device/register');
alert(e.registrationId);
},
error:function(e)
{
Ti.API.error("Error during registration: "+e.error);
var message;
if(e.error == "ACCOUNT_MISSING") {
message = "No Google account found; you'll need to add one (in Settings/Accounts) in order to activate notifications";
} else {
message = "Error during registration: "+e.error
}
Titanium.UI.createAlertDialog({
title: 'Push Notification Setup',
message: message,
buttonNames: ['OK']
}).show();
},
callback:function(e) // called when a push notification is received
{
Ti.API.info('JS message event: ' + JSON.stringify(e.data));
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_MAIN,
flags: Ti.Android.FLAG_ACTIVITY_NEW_TASK | Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED,
className: 'com.company.app.YourActivity',
packageName: 'com.company.app'
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
// This is fairly static: Not much need to be altered here
var pending = Ti.Android.createPendingIntent({
activity: Ti.Android.currentActivity,
intent: intent,
type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
});
var notification = Ti.Android.createNotification({
contentIntent: pending,
contentTitle: 'New message',
contentText: e.data.message,
tickerText: "New message"
});
Ti.Android.NotificationManager.notify(1, notification);
}
});
I keep getting an error when trying to register for C2DM notifications on the device...
Error: Uncaught Type Error: Object # has no method 'register'
I successfully compiled the module using 1.8.2 and it loads but when I try to do:
Any help is greatly appreciated! Thanks!