Notifications! How can I send data with my notifications and receive it in Lua within my Corona App?

I implemented OneSignal, but their example code does little more than allow you to register it with Lua in Corona. It seems to depend upon a greater knowledge of notifications outside of Corona or Lua. Their tech support was responsive, but unable to help because of their lack of understanding about Lua and their plug-in.

Push-woosh, even after paying for their system, was registered, just as with OneSignal above. And I could send some limited notifications, but they were not acting consistent between iOS and Android, despite the fact that registration/login was successful. It operates better than OneSignal, but I still couldn’t get solid, easy to configure, notifications that would allow me to pass data into Corona with access to Lua. After a month, their technical support staff emailed me, “Do you still need help with this?” I answered “Yes” and there was no reply. Another month later I received another similar email, and again, they never replaced to my “Yes.”

So the point is, I have seen no samples anywhere that would provide me the information necessary to successfully sign-up for any notification service and reliably send notifications that would include data that could be passed to my game code in Lua.

This seems to me like an important item that should have a solution posted SOMEWHERE. Are such step-by-step instructions to get beyond a successful registration/login and simple notification, to where useful data can actually be sent and received by code in Lua?

At this point, I am willing to use any reasonable platform to accomplish this. Ideally though, it would be cross-platform and provide me with the opportunity to review metric responses.

Wow! Can someone, anyone, please help me send data through notifications in a manner in which my Lua code can use it? See above.

I’m going to move this to the OneSignal forum. Perhaps someone that frequents that forum can answer you.

Rob, I didn’t put this into OneSignal because my question has more to do with Push-Woosh. However, I don’t care what plantform I use. I’m willing to use ANY PLATFORM that can provide cross-platform support and allow me to pass data from a notification into a Lua call-back. It’s that simple a request. Thus far, I can’t find ANY CORONA SUPPORT for such a simple need. - only basic notifications. Please help.

I am using app42 (shephertz.com) for my push notifications and although I have no need to send custom data with my notifications, according to their docs you can attach metadata to your push notifications. They support Corona on most of their APIs.

Hope this helps!

I spoke too soon. After digging into their docs a little further, I see where the “custom data” function for push notifications in Corona is still under development. However, there are examples in their forum where users have requested a feature and they have produced so it still might be worth your while to check with them. They might be able to assist.

Corona supports this. Your push needs to contain a table called “custom”. This is a table inside the main notification event table.

Thank you. I suppose its just too much to ask for any of these providers to do, at the very least, provide step-by-step instructions. I’m kicking off a project on upWork to do this for ANY push notification service in support of Corona. I’m just shocked that no one can provide me step-by-step instructions in Corona for ANY notification service to do something that virtually any successful title requires. It’s not like I’m a beginning programmer - I’m a 25 year game industry vet.

I don’t have a paid PushWoosh account so I can’t look at their custom data format. If you have an account that can look at that form, perhaps a screen shot would help.

Rob

okay. I have two screen shots of the Corona docs from PushWoosh. But how can I add these images here in this Forum? When I drag either a JPG or PNG into this window, it doesn’t accept the image type. When I click on the image button, it asks me for the URL. When I click My Media, I can not find where to upload the files. And I’ve found no mention of how to do this in the forum documentation. Your continued help is much appreciated.

Click on the “More Reply Options” button at the bottom. You can upload images there.

Rob

Unbelievable! Your forum system gave me “Upload Failed” for JPG, PNG and ZIP files. I’d send you a screen shot, but I can’t. So, I’m sending you the screen shot of the Corona Forum Upload Error and the PushWoosh errors by posting it on my website. Please let me know when you have it so that I can remove it from my site.

www.multimediabible.com/PushWooshCorona.zip

Seriously, it shouldn’t be this difficult to post an image.

test

I’m not sure why you can’t upload them.

Rob

Your images are of the code to support push. I was wanting to the see the screens where you actually entered your push notification to send. There is a place to enter “custom” data. That’s what I’m looking for.

Here you go: www.multimediabible.com/PushWooshCorona2.zip - there is no information anywhere on how to use this.

Try something like:

{ “key1” : “value1”, “key2” : “value2” }

Then in your notification event should have a table called event.custom and it should hold that block of JSON data that you can json.decode() into a Lua table you can use.

Rob

Here is my current code - please be more clear about how to capture the data:

function NT.notificationListener( event )
    if V.notificationsOkay~=0 then
        print( “Notification event.type:”…event.type )
        print( “Notification event.name:”…event.name )    
        if ( event.type == “remote” or event.type == “local” ) then
            --handle the push or local notification
            print(“Notification is REMOVE or LOCAL”)
            print(“event.token:”…tostring(event.token))
            print(“event.text:”…tostring(event.text))
        elseif ( event.type == “remoteRegistration” ) then
            local deviceToken = event.token
            local deviceType = 1  --default to iOS
            if ( system.getInfo(“platformName”) == “Android” ) then
                deviceType = 3
            end
            print( “Setting up with PushWoosh”, event.token )
            local PW_APPLICATION = “xxxxx-xxxxx”  --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
                    native.showAlert( “Notification Registration Failed”, “An Error Contacting the Server has Occurred.”, { “OK” } )
                else
                    --registration successful!
                    print( “PushWoosh registration successful”, V.deviceID)  --system.getInfo(“deviceID”) )
                end
            end    
            
            local commands_json =
            {
                [“request”] = {
                    [“application”] = PW_APPLICATION,
                    [“push_token”] = deviceToken,
                    [“language”] = V.chosenAbbrev,  --system.getPreference( “ui”, “language” ),  --“en”
                    [“hwid”] = V.deviceID,  --system.getInfo(“deviceID”),
                    [“timezone”] = -3600,  --offset in seconds
                    [“device_type”] = deviceType
                }
            }
            
            local post_body = json.encode( commands_json )
            local headers = {}
            headers[“Content-Type”] = “application/json”
            headers[“Accept-Language”] = “en-US”
            local params = {}
            params.headers = headers
            params.body = post_body
            network.request ( PW_URL, “POST”, networkListener, params )
        end
    else
        if ( event.type == “remoteRegistration” ) then
            V.notificationEvent=event
        end
    end
end

Hi Rob, on a similar but separate not, to setup a local notification, this is my code:

    local options = {
        alert = “Come Back to myGame”,
        badge = 2,
        sound = “alarm.caf”,
        custom = { foo = “bar” }
    }
    local newID = notifications.scheduleNotification( 60, options )  --604800 seconds = 1 week

You had mentioned there is a way to remove all notifications when I load up my iOS App? Can you please share that with me here, too?

Please in the future use code formatting for posting code. It’s the blue <> button

function NT.notificationListener( event ) if V.notificationsOkay~=0 then print( "Notification event.type:"..event.type ) print( "Notification event.name:"..event.name ) if ( event.type == "remote" or event.type == "local" ) then --handle the push or local notification print("Notification is REMOVE or LOCAL") print("event.token:"..tostring(event.token)) print("event.text:"..tostring(event.text)) print( json.prettify( event ) ) -- dump the event table elseif ( event.type == "remoteRegistration" ) then local deviceToken = event.token local deviceType = 1 --default to iOS if ( system.getInfo("platformName") == "Android" ) then deviceType = 3 end print( "Setting up with PushWoosh", event.token ) local PW\_APPLICATION = "xxxxx-xxxxx" --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 native.showAlert( "Notification Registration Failed", "An Error Contacting the Server has Occurred.", { "OK" } ) else --registration successful! print( "PushWoosh registration successful", V.deviceID) --system.getInfo("deviceID") ) end end local commands\_json = { ["request"] = { ["application"] = PW\_APPLICATION, ["push\_token"] = deviceToken, ["language"] = V.chosenAbbrev, --system.getPreference( "ui", "language" ), --"en" ["hwid"] = V.deviceID, --system.getInfo("deviceID"), ["timezone"] = -3600, --offset in seconds ["device\_type"] = deviceType } } local post\_body = json.encode( commands\_json ) local headers = {} headers["Content-Type"] = "application/json" headers["Accept-Language"] = "en-US" local params = {} params.headers = headers params.body = post\_body network.request ( PW\_URL, "POST", networkListener, params ) end else if ( event.type == "remoteRegistration" ) then V.notificationEvent=event end end end

The only code I made to your code was adding a print to dump the event table so you can see what you’re getting.

In the PushWoosh interface in that custom field type what I suggested before and send your push notification from PushWoosh.

Rob

On iOS, when the app starts or comes back into the foreground, any notifications you have received will be cleared. Any pending local notifications as long as you have not exited your app can still be canceled with the cancel function. The only thing where it becomes a problem is if you completely exit your app you loose the handles to the notifications and you can’t do much about them.

Rob