Hello,
I am trying to use PushWoosh in my Android app for the first time. I am using the code from their tutorial at the url http://www.pushwoosh.com/programming-push-notification/corona-sdk-ios-push-notifications/ I added it in the main.lue file which is used in my scene app. Below is the code to my main.lua file. Can anyone tell me if I did something wrong?
I changed my PW_APPLICATION for posting. I also left the launchArgs alone because I don’t know what to change that to if needed. And I have the gotoScene after everything. Should I move this somewhere else in the code?
Thanks!
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local storyboard = require "storyboard" storyboard.FBLoggedIn = "N" storyboard.SoundOn = "Y" local launchArgs = ... local json = require "json" if launchArgs and launchArgs.notification then native.showAlert( "launchArgs", json.encode( launchArgs.notification ), { "OK" } ) end -- notification listener local function onNotification( event ) if event.type == "remoteRegistration" then local DeviceID = event.token local PW\_APPLICATION = "xxxxxxxxxxxxxxx" --use your app id in pushwoosh local PW\_URL = "https://cp.pushwoosh.com/json/1.3/registerDevice" local function networkListener( event ) if ( event.isError ) then --error occurred notify user native.showAlert( "Notification Registration Failed", "An Error Contacting the Server has Occurred. Please try again later from the application settings.", { "OK" } ) else --Registration worked perform any action you like here end end local commands\_json = { ["request"] = { ["application"] = PW\_APPLICATION, ["push\_token"] = DeviceID, ["language"] = system.getPreference("ui", "language"), ["hwid"] = system.getInfo("deviceID"), ["timezone"] = 3600, -- offset in seconds ["device\_type"] = 1 } } local jsonvar = {} jsonvar = json.encode(commands\_json) local post = jsonvar local headers = {} headers["Content-Type"] = "application/json" headers["Accept-Language"] = "en-US" local params = {} params.headers = headers params.body = post network.request ( PW\_URL, "POST", networkListener, params ) end end Runtime:addEventListener( "notification", onNotification ) -- load scenetemplate.lua storyboard.gotoScene( "SceneHome" ) -- Add any objects that should appear on all scenes below (e.g. tab bar, hud, etc.):