remote push using pushwoosh - need help with the way the message is displayed

If you want the pop-up to not display then comment out the native.showAlert line near the end of that code.

native.showAlert( "remote", json.encode( event ), { "OK" } )

As for having it show in your app with an icon or just similar to what you see outside in the OS, you will have to create your own code to do that. There is nothing built into Corona for displaying that.

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:

  1. 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.

   

  1. 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.

  2. 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 )

Hi,

When the app is not active iOS handles the notification itself. By clicking on the notification app comes into the foreground.

In general two things can happen:

  1. The app was closed and was started as a result of clicking notification in the Notification Center. So called onstart notification. This code handles this:

if launchArgs and launchArgs.notification then

    native.showAlert( “launchArgs”, json.encode( launchArgs.notification ), { “OK” } )

end

 

  1. The app was active and notification has arrived when the app was in the foreground. This code handles this:

 

    elseif event.type == “remote” then

        native.showAlert( “remote”, json.encode( event ), { “OK” } )

    end

Please note that notification is an array of different key-value pairs. You can control these alerts and the value you want to display or not to display the alert at all.

I hope it helps!

Max

Pushwoosh team.

Max,

         Thanks for the detailed explanation. I am able to display the notification (my sent message) and when the user taps it, my app shows up. For now I have suppressed the alert display. All I need to display is the “pushed message”. what is the key-value pair for the pushed message? I tried  json.encode( launchArgs.alert ) and it displayed a “null”.

thanks

Regards,

Ram

On start it is:  launchArgs.notification.alert

When the app is running I support it is: event.alert, or event.notification.alert

Hi Max,

             The suggested method works great. thank you. 

I have one last question related to this. 

I tried using the advanced form and created a formatted HTML Page and URL, alongside the message and woosh it. All I see is only the message. How does the URL data work and how to display formatted HTML using the “push”?

Appreciate all your help.

thanks

-Ram

I see on the screenshot you’ve pasted, “custom” array is empty in the notification. Do you use Corona SDK that passes custom values from the notification to “custom” array? I know some versions of Corona SDK were missing that functionality…

Hi Max,

              I am using corona Version 2013.1196 (2013.8.22). How do you pass the custom values to the array?

thanks

Regards,

Ram

Hi,

If you go to Pushwoosh control panel, click “edit application”, do you see Corona radio button for iOS and Android selected?

Max,

          Yes. Corona radio button is selected for both IOS and Andorid , under  “edit application”.

Thanks

Regards,

Ram

If you want the pop-up to not display then comment out the native.showAlert line near the end of that code.

native.showAlert( "remote", json.encode( event ), { "OK" } )

As for having it show in your app with an icon or just similar to what you see outside in the OS, you will have to create your own code to do that. There is nothing built into Corona for displaying that.

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:

  1. 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.

   

  1. 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.

  2. 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 )

Hi,

When the app is not active iOS handles the notification itself. By clicking on the notification app comes into the foreground.

In general two things can happen:

  1. The app was closed and was started as a result of clicking notification in the Notification Center. So called onstart notification. This code handles this:

if launchArgs and launchArgs.notification then

    native.showAlert( “launchArgs”, json.encode( launchArgs.notification ), { “OK” } )

end

 

  1. The app was active and notification has arrived when the app was in the foreground. This code handles this:

 

    elseif event.type == “remote” then

        native.showAlert( “remote”, json.encode( event ), { “OK” } )

    end

Please note that notification is an array of different key-value pairs. You can control these alerts and the value you want to display or not to display the alert at all.

I hope it helps!

Max

Pushwoosh team.

Max,

         Thanks for the detailed explanation. I am able to display the notification (my sent message) and when the user taps it, my app shows up. For now I have suppressed the alert display. All I need to display is the “pushed message”. what is the key-value pair for the pushed message? I tried  json.encode( launchArgs.alert ) and it displayed a “null”.

thanks

Regards,

Ram

On start it is:  launchArgs.notification.alert

When the app is running I support it is: event.alert, or event.notification.alert

Hi Max,

             The suggested method works great. thank you. 

I have one last question related to this. 

I tried using the advanced form and created a formatted HTML Page and URL, alongside the message and woosh it. All I see is only the message. How does the URL data work and how to display formatted HTML using the “push”?

Appreciate all your help.

thanks

-Ram

I see on the screenshot you’ve pasted, “custom” array is empty in the notification. Do you use Corona SDK that passes custom values from the notification to “custom” array? I know some versions of Corona SDK were missing that functionality…

Hi Max,

              I am using corona Version 2013.1196 (2013.8.22). How do you pass the custom values to the array?

thanks

Regards,

Ram

Hi,

If you go to Pushwoosh control panel, click “edit application”, do you see Corona radio button for iOS and Android selected?

Max,

          Yes. Corona radio button is selected for both IOS and Andorid , under  “edit application”.

Thanks

Regards,

Ram