Error with Push Woosh

Hi everybody, 

i tried notification push with push woosh, and i worked. 
I success to send and receive notification to devices which have the app, but there are some errors. 

The first is the logo of the notification, i don’t understand how i can have the good logo in the notification, actually i have a sign with an exclamation point instead of the logo of my app. 

The second is more important, when i open the notification push, i have this error : 

4540011058963710202290097590389163576362

if you have a idea…

1.  Please read this guide:  http://docs.coronalabs.com/guide/events/appNotification/index.html#android

Specially the segment on Android Icons.

2.  This is not an error.  In your code you  have a native.showAlert() that is taking the event data from the push notification and using JSON to turn it into a string that’s being printed by the native.showAlert().  It’s your responsibility to handle the inbound notification and do something with it.    Perhaps you just want your native.showAlert() to show the " alert" value from the table.

Rob

ok for logo, i will work on. 

For the problem with JSON, i read this topic : http://forums.coronalabs.com/topic/49410-having-a-nightmare-with-push-notifications-please-help/?hl=%2Bpush+%2Bwoosh 

where you explain, but i didn’t understand where is the problem on my code. 

If you have the time to help me my code is (there is just notification push on it) : 

local launchArgs = ... local json = require "json" if launchArgs and launchArgs.notification then native.showAlert( "launchArgs", json.encode( launchArgs.notification ), { "OK" } ) end local function registerWithPushWoosh (token) -- Register device with PushWoosh. PushWoosh account and setup required. local DeviceID = token local PW\_APPLICATION = "5FD15-EA06D" --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", { "OK" } ) else --Registration worked 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"] = 3 -- 1 – iphone, 2 – blackberry, 3 – android, 4 – nokia, 5 – WP7, 7 – mac } } 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 ) end local function onNotification( event ) if event.type == "remoteRegistration" then registerWithPushWoosh(event.token) end end Runtime:addEventListener( "notification", onNotification )
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.

ok thank you for your explanations i think that i understood. 

so my code is now like that : 

local launchArgs = ... local json = require "json" if launchArgs and launchArgs.notification then native.showAlert( "launchArgs", json.encode( launchArgs.notification ), { "OK" } ) 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. end local function registerWithPushWoosh (token) -- Register device with PushWoosh. PushWoosh account and setup required. local DeviceID = token local PW\_APPLICATION = "5FD15-EA06D" --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", { "OK" } ) else --Registration worked 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"] = 3 -- 1 – iphone, 2 – blackberry, 3 – android, 4 – nokia, 5 – WP7, 7 – mac } } 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 ) end local function onNotification( event ) if event.type == "remoteRegistration" then registerWithPushWoosh(event.token) else 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. -- put code here to handle your push notification end end Runtime:addEventListener( "notification", onNotification ) 

i didn’t test for the moment, but i think that it’s the good changement, according to what you explained

This:

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.

and

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.
        – put code here to handle your push notification

Are not usable code.  I was explaining to you what values were in the tables that are being given to you.

ah, i didn’t understand, so excuse me a lot of because i don’t know where i must put this on my code. 
I’m sorry of don’t understand… 

Don’t be offended by this, but you might be trying to do something too hard for your experience.  We really want you to be successful and it might be worth holding off on this project and spending some more time going through more tutorials and trying to build some simpler projects until you understand basic data passing between functions and understand tables more.

Rob

surely you are right, but it’s the last things to have a good app. 
Notification push is a hard code, in addition i’m french and i try to understand all your explanations. 
 

i will not ask to you : can you write my code ? 
just : where i can learn or work for success on notification push with Push Woosh?

You have to ask  yourself a question first.  What do you want to happen when your app gets a push notification?  Do you just want to show the message sent in an alert box?

If so, then all you need to do is:

local function onNotification( event )     if event.type == "remoteRegistration" then          registerWithPushWoosh(event.token)     else         native.showAlert( "Your App Name here", event.alert, { "Okay" } )     end end

for your onNotification block and then:

if launchArgs and launchArgs.notification then     native.showAlert( "Your App Name", launchArgs.notification.alert, { "Okay" } ) end

for your launchArgs handler.

i understand now !!
i write your code, and it’s work, i have only the alert box but without any error! 

now  i understand your words :’'What do you want to happen when your app gets a push notification?"

​in push woosh with a notification i can in more send a Rich HTML page, a page that i make and which is displayed above the screen of my app, before my app just after the notification. 
What i must put on my code to see it ? 

Thanks a lot 

Without seeing what Pushwoosh is sending you, it’s going to be very hard to advise you on what to do.  That’s why the alert that was there was json.encode()'ing your push event data so you could see what all was being sent.  In the example above, the custom table is empty.  This is where any information regarding a rich message would exist. 

Rob

Hi Rob, 

with pushwoosh i can send a notification with additional data, i create a rich html page in their website, and push woos send my notification with the rich page, and when i receive my notification and i click in “OK”, my device go on the home page of my app and no on the rich html page. 

 

i show you the screen of the config in pushwoosh, i think that the problem is on my lua, but i don’t understand how i can change it… 

 

248878Capturedcran20140901111621.png

 

i understand that the problem have a link with json.encode() that i delete, because i have the error of the beginning… 

Can you print out the contents of the notification? 

print( json.encode( event.notification ) )

Without dumping the contents of the notification event, you won’t know what’s there and how to use it.  Tomorrow’s tutorial on the blog will present you a table printing function which may be easier for you to use than trying to read the json encoded string.

Keep in mind, we cannot officially support pushwoosh, or any 3rd party push service.  I’m not sure how the rich HTML is supposed to work.  You should be able to create a block of JSON data and put it in the custom field and we should be able to use that.

Rob

I am also facing the same problem. I tested a ‘banner’ and also rich-html on PushWoosh, but nothing appeared on my Android app.

Here’s the log from remote notification. Looks really plain and simple without any html link in it…

I/Corona ( 5976): ### type: remote I/Corona ( 5976): ### name: notification I/Corona ( 5976): ### custom I/Corona ( 5976): ### { I/Corona ( 5976): ### } I/Corona ( 5976): ### alert: rich notification I/Corona ( 5976): ### applicationState: inactive

another log :

I/Corona (18285): ### type: remote I/Corona (18285): ### name: notification I/Corona (18285): ### custom I/Corona (18285): ### { I/Corona (18285): ### } I/Corona (18285): ### alert: rich notification I/Corona (18285): ### applicationState: inactive

Pushwoosh, like most 3rd party vendors offers a service.  We cannot control how they do things and as such we can’t provide support for them.

This is very likely a case of where they are sending some data that we don’t recognize.  The custom table is empty which is where we expect custom data to exist.  I know that Pushwoosh has a “Custom” field that you can drop JSON code into.  I don’t know how or what their Rich HTML is supposed to be sending.

If it’s just a URL, I would suggest creating a JSON string and put it in the custom field:  Perhaps try:

“URL”: "http://yoururl.com"

If that doesn’t work

{ “URL”: “http://yoururl.com” }

and finally:

[{ “URL”: “http://yoururl.com” }]

or whatever the valid JSON format is for that and see what shows up in our custom table.

Putting in the extra data in JSON works, but i was hoping to be able to show an image in notification (kinda like how groupon and the rest does it).

The problem is I don’t see this in GCM docs, so I guess it is how the app manages the data received from GCM.

If i push the message manually to GCM, what kinda of data is required to show an image in the notification bar ? 

I/Corona (32128): ### type: remote I/Corona (32128): ### name: notification I/Corona (32128): ### custom I/Corona (32128): ### { I/Corona (32128): ### URL: http://yoururl.com I/Corona (32128): ### } I/Corona (32128): ### alert: hhhelo I/Corona (32128): ### applicationState: inactive

I tried to find the format of their Rich Push notifications.  If they are not putting it in the custom table, there is no way to retrieve it without some engineering efforts.

Rob

Thanks Rob. I have contacted PushWoosh and hopefully they will reply in this thread.

1.  Please read this guide:  http://docs.coronalabs.com/guide/events/appNotification/index.html#android

Specially the segment on Android Icons.

2.  This is not an error.  In your code you  have a native.showAlert() that is taking the event data from the push notification and using JSON to turn it into a string that’s being printed by the native.showAlert().  It’s your responsibility to handle the inbound notification and do something with it.    Perhaps you just want your native.showAlert() to show the " alert" value from the table.

Rob