Unable to send Custom Data to iOS (2014)

I am not able to send custom data to iOS via push notifications and it’s not clear why.

Since I am very new to corona, I assume this is my error. However, I don’t know how to resolve.

I previously implemented urbanairship as my provider for push, as they are mentioned on the corona docs as a provider. However, after google turned up several people also with this exact issue - and no resolution, I switched providers to PushWoosh, hoping it would resolve the issue.

I am attempting to send a message from python (via rest/POST) to pushwoosh. While notifications are delivered, custom data is not sent to the device. Or, if it is sent to the device, it’s not appearing in the onNotification event. Or, some other error is occurring. 

  • Implemented pushwoosh
  • able to receive push notifications on the device
  • custom data always empty.
  • Updated Config.lua to include “custom” even though this is never explicitly mentioned in the docs.

    notification = { iphone = { types = { “badge”, “sound”, “alert”, “custom” } } },

Read and reviewed teh following posts on this specific subject; none of which resolve the issue.

Custom data is always returned as an empty array “[]” instead of an empty object to the device. Though, preferably, it wouldn’t be empty at all. Which, as noted in other posts, appears to be an “upstream” conversion as Perry said in the aforementioned posts.

Payload returned to device as json.encode(event).

{"type":"remote","name":"notification","custom":[],"sound":"default","alert":"We all love notifications","applicationState":"active"} null

The pushwoosh documentation says it will return custom data as the"u" parameter. But there is no such parameter in the event object.

// JSON string or JSON object, will be passed as “u” parameter in the payload

Python JSON data to construct request. Out of desperation, I have “peppered” the data going to pushwoosh with some extra custom data, hoping something might be delivered.

 data = { "request":{ "application":app\_code, # "applications\_group":"GROUP\_CODE", "auth":api\_access\_token, "notifications":[{ "send\_date":"now", "content":msg, "ios\_root\_params":{ "extra":{"motherfoo":"bar"}, "aps":{ "content-available": "1" } }, "data":{ # // JSON string or JSON object, will be passed as "u" parameter in the payload "custom": {"foo":True, "what":"lol"}, "extra": {"foo2extra":True, "what":"lol"} }, "custom": {"topfoo":True}, "platforms": [1], "devices":[device\_token], }] } }

Current Lua / Corona SDK code (Essentially the example code on pushwoosh)

local function onNotification( event ) print("onNotification()", json.encode(event), json.encode(event.u)) if event.type == "remoteRegistration" then local device\_token = event.token local PW\_APPLICATION = "MY APP TOKEN" -- use your app id in pushwoosh local PW\_URL = "https://cp.pushwoosh.com/json/1.3/registerDevice" local deviceType = 1 --// default to iOS if ( system.getInfo("platformName") == "Android" ) then deviceType = 3 end 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"] = device\_token, ["language"] = system.getPreference("ui", "language"), ["hwid"] = system.getInfo("deviceID"), ["timezone"] = 3600, -- // offset in seconds ["device\_type"] = deviceType } } 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("Custom data is ", event.custom, json.encode(event.custom)) native.showAlert( "My Game", event.alert, {"OK"} ) end end Runtime:addEventListener( "notification", onNotification )

Corona version info

Basic 2014.2189

Note: the Corona SDK docs for implementing push point to a full reference, which doesn’t actually mention anything about notifications.

In addition, you must include a notification table in the config.lua file (reference) to enable various features for push notifications. This tells the system which of the alert types you plan to use.

Additional reference materials

http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-Method-messages-create

http://docs.coronalabs.com/guide/distribution/iOSBuild/index.html

Hi Gregory, we support custom data with our Corona push notification plugin: http://docs.coronalabs.com/daily/plugin/GameThrivePushNotifications/index.htmlhttps://gamethrive.com

If I was to guess why PushWoosh or UrbanAirship aren’t working though, I think it’s because Corona requires you to nest any custom data under a “custom” field at the root of the data (instead of “u” like PushWoosh does)

The notification that gets composed needs to look something like this:

{
alert:“An alert with custom data”,
badge: 1,
sound: “default”,
custom: { foo: “bar” }
}

And the custom data you will get is { foo: “bar” }. Hopefully PushWoosh or UrbanAirship let you compose messages in this format, but otherwise it’s something we support by default in GameThrive.

Hope that helps!

Hi george18

Thanks for the thoughts! Wish you guys listed prices for push services clearly on your site.

As you will notice from the python data posted above, I have tried to put that ‘custom’ bit in about every place I can imagine it going. Additionally, for urbanarship I tried their existing python library, as well as a fork. Then finally, I gave up and wrote my own custom python snippet to post the custom JSON object onto several different places in the request. None of which worked unfortunately.

Pushwoosh notes that the “u” attribute would be returned to the device. However, as can be seen on the above object as well as the pushwoosh docs, pushwoosh appears to want to translate data.custom to ‘u’ on the device. Urbanairship called it extra and it’s unclear how it would be delivered on device.

Since I am catching the notification event via corona, it’s unclear if corona is dropping any values. Since Perry said in one of the linked posts, that they are just passing custom through, I have to assume it’s a no, but perhaps a staff member can clarify this point.

Price of GameThrive is free for Corona developers (even if you exceed our normal free plan limits)

The issue with your python example is that once PushWoosh receives that API call from you, they end up transforming it into a format where anything you put inside of “custom” from their API or dashboard gets nested under “u” in their system before they send it to Apple or Google’s and it’s delivered to your app (as is noted in their documentation comment).

Ultimately the problem arises from a quirk in Corona. If you were building a native app, for instance, it would be just fine that PushWoosh puts things under the “u” field (or any other field name for that matter). But Corona specifically requires that the field be called “custom” instead. As a result, I don’t think it’s possible to send custom data to a Corona app with PushWoosh.

We ran into this Corona quirk ourselves when building GameThrive so we made sure that our data is transferred under a field with the name “custom”, and therefore fully compatible with Corona apps.

Hope that all makes sense!

This issue was resolved via a cross post on pushwoosh for this error and relates to the location of where

“custom” is placed as george18 theorized. 

The solution on pushwoosh forums:

https://community.pushwoosh.com/questions/680/unable-to-send-custom-data-to-ios-using-corona-sdk-python/684

python JSON request structure to send to pushwoosh

 data = { "request":{ "application":app\_code, # "applications\_group":"GROUP\_CODE", "auth":api\_access\_token, "notifications":[{ "send\_date":"now", "content":msg, "ios\_root\_params":{ "custom": { "aboolean":False, "astring":"apstop", "anarray":[1,2,3,4,5], "aninteger":55, "afloat":550.556, "adict":{"foo":"bar"}, }, }, "platforms": [1], "devices":[device\_token], }] } }

Corona / Lua print output

{"aboolean":false,"anarray":[1,2,3,4,5],"afloat":550.556,"aninteger":55,"astring":"apstop","adict":{"foo":"bar"}}

Hi Gregory, we support custom data with our Corona push notification plugin: http://docs.coronalabs.com/daily/plugin/GameThrivePushNotifications/index.htmlhttps://gamethrive.com

If I was to guess why PushWoosh or UrbanAirship aren’t working though, I think it’s because Corona requires you to nest any custom data under a “custom” field at the root of the data (instead of “u” like PushWoosh does)

The notification that gets composed needs to look something like this:

{
alert:“An alert with custom data”,
badge: 1,
sound: “default”,
custom: { foo: “bar” }
}

And the custom data you will get is { foo: “bar” }. Hopefully PushWoosh or UrbanAirship let you compose messages in this format, but otherwise it’s something we support by default in GameThrive.

Hope that helps!

Hi george18

Thanks for the thoughts! Wish you guys listed prices for push services clearly on your site.

As you will notice from the python data posted above, I have tried to put that ‘custom’ bit in about every place I can imagine it going. Additionally, for urbanarship I tried their existing python library, as well as a fork. Then finally, I gave up and wrote my own custom python snippet to post the custom JSON object onto several different places in the request. None of which worked unfortunately.

Pushwoosh notes that the “u” attribute would be returned to the device. However, as can be seen on the above object as well as the pushwoosh docs, pushwoosh appears to want to translate data.custom to ‘u’ on the device. Urbanairship called it extra and it’s unclear how it would be delivered on device.

Since I am catching the notification event via corona, it’s unclear if corona is dropping any values. Since Perry said in one of the linked posts, that they are just passing custom through, I have to assume it’s a no, but perhaps a staff member can clarify this point.

Price of GameThrive is free for Corona developers (even if you exceed our normal free plan limits)

The issue with your python example is that once PushWoosh receives that API call from you, they end up transforming it into a format where anything you put inside of “custom” from their API or dashboard gets nested under “u” in their system before they send it to Apple or Google’s and it’s delivered to your app (as is noted in their documentation comment).

Ultimately the problem arises from a quirk in Corona. If you were building a native app, for instance, it would be just fine that PushWoosh puts things under the “u” field (or any other field name for that matter). But Corona specifically requires that the field be called “custom” instead. As a result, I don’t think it’s possible to send custom data to a Corona app with PushWoosh.

We ran into this Corona quirk ourselves when building GameThrive so we made sure that our data is transferred under a field with the name “custom”, and therefore fully compatible with Corona apps.

Hope that all makes sense!

This issue was resolved via a cross post on pushwoosh for this error and relates to the location of where

“custom” is placed as george18 theorized. 

The solution on pushwoosh forums:

https://community.pushwoosh.com/questions/680/unable-to-send-custom-data-to-ios-using-corona-sdk-python/684

python JSON request structure to send to pushwoosh

 data = { "request":{ "application":app\_code, # "applications\_group":"GROUP\_CODE", "auth":api\_access\_token, "notifications":[{ "send\_date":"now", "content":msg, "ios\_root\_params":{ "custom": { "aboolean":False, "astring":"apstop", "anarray":[1,2,3,4,5], "aninteger":55, "afloat":550.556, "adict":{"foo":"bar"}, }, }, "platforms": [1], "devices":[device\_token], }] } }

Corona / Lua print output

{"aboolean":false,"anarray":[1,2,3,4,5],"afloat":550.556,"aninteger":55,"astring":"apstop","adict":{"foo":"bar"}}