Game Development Reference
In-Depth Information
local action, data, title
if event.action then action = event.action end
if event.data then data = event.data end
if event.title then title = event.title end
print("Message : " .. message)
print("action : " .. action)
print("data : " .. data)
print("title : ", title)
end
MOAINotification.setListener(MOAINotification.REMOTE_NOTIFICATION_REGISTRATION_COMPLETE, onRegComplete)
MOAINotification.setListener(MOAINotification.REMOTE_NOTIFICATION_MESSAGE_RECEIVED, onRemoteNotification)
MOAINotification.setAppIconBadgeNumber(0)
MOAINotification.registerForRemoteNotification(
MOAINotification.REMOTE_NOTIFICATION_BADGE +
MOAINotification.REMOTE_NOTIFICATION_ALERT)
Networking
In your game, you might need to download level data or some other data using the HTTP or HTTPS
protocol. Moai has a MOAIHttpTask class that allows for downloading data from an HTTP/S source.
function onDone(task, responseCode)
print("Downloaded", responseCode)
if task:getSize() then
print(task:getString())
else
print("Got nothing")
end
end
theTask = MOAIHttpTask.new("Download Webpage")
theTask:setCallback(onDone)
theTask:httpGet(" http://www.oz-apps.com " )
The httpGet function works synchronously; however, if you want that the data be loaded
asynchronously , you need to call the performAsync function instead:
function onFinish ( task, responseCode )
print ( "onFinish" )
print ( responseCode )
if ( task:getSize ()) then
print ( task:getString ())
else
print ( "nothing" )
end
end
 
Search WWH ::




Custom Search