The Curl code below will send a message to Urban Airship and return a Push Notification to my iPhone.
curl -X POST -u "xxxxx my id xxx" \
-H "Content-Type: application/json" \
--data '{"device\_tokens": ["xxxmy device tokenxxx"], "aps": {"alert": "Hello!"}}' \
https://go.urbanairship.com/api/push/
I want to accomplish the same thing in Lua using network.request.
“Akviby” accomplished the task to get a device recognized by Urban Airship, which works. You can send a message to your device by using the Curl script above but how would you do it in Lua?
His forum URL:
http://developer.anscamobile.com/forum/2011/12/22/corona-sdk-push-notifications-and-urban-airship-solved
I tried to modify his code with the following below:
It gets to Urban Airship but returns an error. I am having difficulty on what the headers, body and subsequent params should look like.
Anybody have any clues? Can anyone breakdown the Curl script into a workable URL.
My code:
[code]
local mime = require( “mime” )
–** Modfied code form Url mentioned above **
– Here is the implementation of Push Notification in Corona SDK
local launchArgs = …
APPKEY = “xxx”
APPLICATIONSECRET = “xxx”
– Function to handle Network Traffic Response from Urban Airship
local function urbanNetworkListener( event )
if ( event.isError ) then
native.showAlert( “Network error!”, “Error has occured from Urban Airship”, {“OK”})
else
native.showAlert( “Urban Airship”, event.response, {“OK”})
end
end
local buttonScore = display.newImage( “hello.png” )
buttonScore.x = 100
buttonScore.y = 100
–****************************************************************
function buttonScore:tap(event)
–****************************************************************
local secretString = mime.b64(APPKEY … “:” … APPLICATIONSECRET)
mytokens = “xxxx”
message = “alert” …“Hello!”
headers = {}
headers[“Content-Type”] = “application/json”
–was here headers[“Authorization”] = "Basic " … secretString
– body =
local params = {}
params.headers = headers
params.device_tokens = mytokens
params.Alert = message
network.request( “https://go.urbanairship.com/api/” … secretString, “PUSH” , urbanNetworkListener, params)
end
buttonScore:addEventListener(“tap”, buttonScore)
[/code] [import]uid: 22152 topic_id: 22121 reply_id: 322121[/import]