I’m researching push and have successfully gotten Android push to work both from my own server and with Pushwoosh. But it looks like Urban Airship is my best option but I can’t get device registration to work with Android. Not that iOS is working either but lets start with Android.
My code is as follows:
-- Code uses pr() function that is not included. It just dumps out table values for debugging local function registerWithUrbanAirship ( deviceToken ) -- Catch whatever Urban Airship returns local function urbanNetworkListener( event ) if ( event.isError ) then pr(event, 'Urban airship not responding') else pr(event, 'Urban airship response') end local mime = require( "mime" ) local APPKEY = "XXXXXXXXX" local APPLICATIONSECRET = "XXXXXXXXX" -- I have tried skipping this encryption but same result. local secretString = mime.b64(APPKEY .. ":" .. APPLICATIONSECRET) local headers = {} headers["Authorization"] = "Basic " .. secretString headers["Content-Type"] = "application/json" local params = {} params.headers = headers params.body = "" network.request( "https://go.urbanairship.com/api/device\_tokens/" .. deviceToken, "PUT", urbanNetworkListener, params) end local function onNotification( event ) if event.type == "remoteRegistration" then pr(event, 'remote registration') registerWithUrbanAirship ( event.token ) else -- A push notification has just been received. pr(event, 'Notification recieved') end end Runtime:addEventListener( "notification", onNotification )
Android results from pr() function:
remote registration = { | type = "remoteRegistration", | name = "notification", | token = "tokenEditedOut", }, Urban airship response = { | responseHeaders = { | | Connection = "close", | | Content-Length = "222", | | Date = "Tue, 04 Jun 2013 05:19:39 GMT", | | X-Android-Sent-Millis = "1370323178437", | | Expires = "Tue, 04 Jun 2013 05:19:39 GMT", | | X-Android-Received-Millis = "1370323178599", | | Content-Type = "text/html", | | Mime-Version = "1.0", | | HTTP-STATUS-LINE = "HTTP/1.1 411 Length Required", | | Server = "AkamaiGHost", | }, | responseType = "text", | phase = "ended", | bytesEstimated = 222, | response = "\<HTML\>\<HEAD\> \<TITLE\>Bad Request\</TITLE\> \</HEAD\>\<BODY\> \<H1\>Bad Request\</H1\> Your browser sent a request that this server could not understand.\<P\> Reference #7.55acefca.1370323179.42a5a31 \</BODY\> \</HTML\> ", | name = "networkRequest", | bytesTransferred = 222, | status = 411, | url = "https://go.urbanairship.com/api/device\_tokens/myTokenEditedOut", | isError = false, | requestId = "false", },