Hello everyone,
I’m trying to use push notification on my app but having trouble making it work. I am using pushwoosh right now. I followed all of the instruction from the documentation here. Put these codes on my config.lua
[lua]
application = {
content = {
width = 320,
height = 480,
scale = “letterBox”,
fps = 30,
},
notification = {
google = {
projectNumber = “3982849975315”
},
}
}
[/lua]
here is my main.lua. I replaced “PUHSOOWH_APPLICATION_ID” with my apps pushwoosh id.
[lua]
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 = “PUHSOOWH_APPLICATION_ID” --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
native.showAlert(“Push notification ready”, “You can now receive push notifications.”, {“Close”});
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 )
elseif event.type == “remote” then
native.showAlert( “remote”, json.encode( event ), { “OK” } )
end
end
Runtime:addEventListener( “notification”, onNotification )
[/lua]
I also put these codes on build.settings because the app crashes if I don’t include the permissions.
[lua]
settings = {
orientation = {
default = “portrait”,
supported = { “portrait”, }
},
iphone = {
plist = {
UIStatusBarHidden = false,
UIPrerenderedIcon = true,
}
},
android = {
permissions = {
{ name = “.permission.C2D_MESSAGE”, protectionLevel = “signature” },
},
usesPermissions = {
“android.permission.INTERNET”,
“android.permission.GET_ACCOUNTS”,
“android.permission.RECEIVE_BOOT_COMPLETED”,
“com.google.android.c2dm.permission.RECEIVE”,
“.permission.C2D_MESSAGE”,
},
},
}
[/lua]
I tried sending a push message but the app doesn’t receive any push notifications at all. What did I missed?
I also tried parse but didn’t worked as well. I’m having a hard time with Urban Airship so I skipped it. Can anyone help me? Thanks.