Hi AndeRoth,
Thanks for the help. Commenting out the native.showAlert, works when the app is in the background. The device displays the notification and if the user taos it, it brings the app to the foreground. This unfortunately does not work if the app is already active. Then the notification itself is not displayed. If the app is inactive then the notification is displayed and then if the user taos it, the encoded pop-up still shows up.
I did some debugging and this is what I found:
- If the app is inactive, the terminal displays debug 1 , inside the very first “if” when the notification comes to the device.
if the user taps on the notification, then the terminal displays debug 2 and the pop-up with the encoded values
The control never comes to debug 1, if the app is active or in the background.
-
If the app is in the background, the terminal displays debug 2, when the notification is displayed. when the user taps the notification, the app comes to the foreground, with terminal displaying debug 3 and no pop-up is displayed, so this scenario works well.
-
If the app is active, then the terminal displays debug 3 and no notification or pop-up.
===========================
local launchArgs = …
local json = require “json”
if launchArgs and launchArgs.notification then
print(“here at the beginning - launchargs”) --debug 1
native.showAlert( “launchArgs”, json.encode( launchArgs.notification ), { “OK” } )
end
– notification listener
local function onNotification( event )
if event.type == “remoteRegistration” then
print(" inside listener - remoteregistration" ) --debug 2
--native.showAlert( “remoteRegistration”, event.token, { “OK” } )
local DeviceID = event.token
local PW_APPLICATION = “C327E-C1959” --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 )
elseif event.type == “remote” then
print(" inside listener - else" ) --debug 3
– native.showAlert( “remote”, json.encode( event ), { “OK” } )
– native.showAlert( “remote”, json.encode( launchArgs.notification ) , { “OK” } )
end
end
Runtime:addEventListener( “notification”, onNotification )