if launchArgs and launchArgs.notification then native.showAlert( "launchArgs", json.encode( launchArgs.notification ), { "OK" } ) end
These three lines will process your push notification **IF** the app is closed and the user interacts with the push notifications from the notification center. All it’s doing is converting the launchArgs.notification table to a string using json.encode. If you want your app to do anything with the notification **when your app starts** then you would put that code inside of that if statement. The launchArgs.notification is a table with the following members in it:
launchArgs.notification.type = “remote” – will always be this.
launchArgs.notification.name = “notification” – will always be this.
launchArgs.notification.alert = “whatever message you sent with pushwoosh” – you probably want to display this.
launchArgs.notification.applicationState = “inactive” – it will always be this.
There is also launchArgs.notification.custom, which is another table, but it appears to be empty. I don’t know that PushWoosh puts anything here.
Now **IF** your app is in the foreground when the notification comes in **OR* * it’s backgrounded and the user interacts with the notification in the notification center, your app will receive a notification event. Your app is currently **NOT** handling this.
local function onNotification( event ) if event.type == "remoteRegistration" then registerWithPushWoosh(event.token) end end Runtime:addEventListener( "notification", onNotification )
Your notification handler is only handling the remoteRegistration event and not the remote notification event. You should consider changing this to:
local function onNotification( event ) if event.type == "remoteRegistration" then registerWithPushWoosh(event.token) else -- put code here to handle your push notification end end Runtime:addEventListener( "notification", onNotification ) In this case, the event table will hold your notification event: event.type = "remote" -- will always be remote if you received a push notification, local if its a local notification or remoteRegistration if it's a registration event (which you are currently handling) event.name = "notification" -- will always be this. event.alert = "whatever message you sent with pushwoosh" -- you probably want to display this. event.applicationState = "active" -- it will active (I think) if your app is in the foreground, or inactive if you were backgrounded.
It’s up to you to decide what you want to do with the notification event.