Retrieve the device token for APN
Hello Guys
I'm trying to implement the push notification , first time a dialog box shows up and i allowed , but didn't store the device token .
Now i cant send the notifications without the device token , how can i retrieve that ?
I've tried Titanium.Network.remoteDeviceUUID and it returns null
and Titanium.Platfrom.id returns the UUID .
Please help.
1 Answer
-
I am using easyapns and set up my script using the following block of code, but this will work with almost any apn server since all the info is required.
loginWindow.add(label); // register for push notifications Titanium.Network.registerForPushNotifications({ types: [ Titanium.Network.NOTIFICATION_TYPE_BADGE, Titanium.Network.NOTIFICATION_TYPE_ALERT, Titanium.Network.NOTIFICATION_TYPE_SOUND ], success:function(e) { var deviceToken = e.deviceToken; label.text = "Device registered. Device token: \n\n"+deviceToken; Ti.API.info("Push notification device token is: "+deviceToken); Ti.API.info("Push notification types: "+Titanium.Network.remoteNotificationTypes); Ti.API.info("Push notification enabled: "+Titanium.Network.remoteNotificationsEnabled); var request = Titanium.Network.createHTTPClient(); request.onload = function() { Ti.API.info('in utf-8 onload for POST'); }; request.onerror = function() { Ti.API.info('in utf-8 error for POST'); }; request.open("GET","http://somesite.com/apns/apns.php?task=register&appname=appname&appversion="+escape(Titanium.App.version)+"&deviceuid="+escape(Titanium.Platform.id)+"&devicetoken="+escape(e.deviceToken)+"&devicemodel="+escape(Titanium.Platform.model)+"&devicename=tester&deviceversion="+escape(Titanium.Platform.version)+"&pushbadge=enabled&pushalert=enabled&pushsound=enabled"); request.send(); }, error:function(e) { label.text = "Error during registration: "+e.error; }, callback:function(e) { // called when a push notification is received. alert("Received a push notification\n\nPayload:\n\n"+JSON.stringify(e.data)); } });