Additional data using ghost and crashes

Hi,

Im trying to send additional data throu the http api lika this 

[“data”] = {{[“abc”] = “123”, [“foo”] = “bar”}},

But that makes all messages on android being Queued, and on iphone they are received when inActive but it crashes the app when opened. But if I send the same data from gamethrive webpage then everything goes well. What am I doing wrong here and why is It only crashed when sending through the server api?  

Could you share the code you’re using to send the request to our API?

Sure thing =)) Thanks…

function SendJson(url, action, in\_json, callback) local headers = {} headers["Authorization"] = "Basic " .. "XXXXXXXXXXX" headers["Content-Type"] = "application/json" headers["Accept-Language"] = "en-US" local params = {} params.headers = headers params.body = json.encode( in\_json ) network.request ( url, action, callback, params ) end function skickaPush ( event ) myApp.settings = loadsave.loadTable("settings.json") local finalPush = "ID:" .. myApp.settings.userId .. ": " .. pushMsg --[[b64 encoding local function \_b64enc(data) local len = data:len() local t = {} for i=1,len,384 do local n = math.min(384, len+1-i) if n \> 0 then local s = data:sub(i, i+n-1) local enc, \_ = mime.b64(s) t[#t+1] = enc end end return table.concat(t) end encodedPush = \_b64enc(pushMsg) --]] local function networkListener( event ) if ( event.isError ) then print( "Network error!") audio.play( myApp.soundTable["fallAndSplat"] ) local ooopsAlert = native.showAlert( "Ooops", "Push ej skickat, vänligen kontrollera nätverksinställningarna eller försök igen", { "OK" } ) else print ( "RESPONSE: " .. event.response ) audio.play( myApp.soundTable["hahaha"] ) myApp.titleText:morphText( "Ditt medelande är skickat!" , 2000) end end local jsonToSend = {["app\_id"] = "XXXXXXXXXXXX", --["headings"] = {["en"] = fromText}, ["contents"] = {["en"] = finalPush}, ["isAndroid"] = true, ["isIos"] = true, --["included\_segments"] = "All" --["wp\_sound"] = "CartoonHop.wav", ["data"] = {{["abc"] = "123", ["foo"] = "bar"}}, ["tags"] = {{["key"] = "iFreduser", ["relation"] = "=", ["value"] = tillId}}, } loadsave.saveTable(jsonToSend, "send.json") SendJson("https://gamethrive.com/api/v1/notifications", "POST", jsonToSend, networkListener) end

I think the issue might be that you’re wrapping the data value inside an extra set of brackets “{” and “}”

Does it work if you change it to this?

[“data”] = {[“abc”] = “123”, [“foo”] = “bar”},

Yes, no more crashes, thank you =)) And there not being queued on android. On iphone push messages are being received even thou the app in no longer active for a short time, after like anything between 30min to 1 hour the push is not being received even thou the server says that it was, on android the app has to be at least in the background to se push even it it according to the server has been sent to the app. Is this the way its supposed to be? Wouldn’t it better if possible that the push is queued until it is possible for the phone to receive it? I can se in my logs in xcode and logcat that nothing has happened in the background so the pushes are not being rejected.

That’s odd. Is this with iOS 8.1? When the app was no longer active, did you manually close the app from the task switcher?

This is with iOS 8.0.2, been to lazy to update :stuck_out_tongue: Is your second question on iphone or android? On the droid its when I manually closed the app. On the iphone its a bit more random, has happened when my phone has gone to sleep by its self while the app was still running. And sometimes inactive for a longer amount of time, like over the night. But on the last case Im not sure If i have closed the app or not. Let me pay some attention and get back to you.

By manually closing on Android are you doing it with code or by pressing the recent apps button and swiping it close? Also what version of Android and Corona Build are you testing on?

On iOS are you testing with a development(sandbox) or production push certificate? If your internet connection is not stable you might not receive a sandbox notification. From my testing it seems Apple just tries once to send the notification in this environment.

Thanks.

Its by manually closing the app from settings meny on android after existing the app. Its a development certificate on iOS, that could be the issue then =)) Ive now put my phone to always be on 3g with seems to be more stable then the wifi at the moment. Thanks for the info :slight_smile:

Could you share the code you’re using to send the request to our API?

Sure thing =)) Thanks…

function SendJson(url, action, in\_json, callback) local headers = {} headers["Authorization"] = "Basic " .. "XXXXXXXXXXX" headers["Content-Type"] = "application/json" headers["Accept-Language"] = "en-US" local params = {} params.headers = headers params.body = json.encode( in\_json ) network.request ( url, action, callback, params ) end function skickaPush ( event ) myApp.settings = loadsave.loadTable("settings.json") local finalPush = "ID:" .. myApp.settings.userId .. ": " .. pushMsg --[[b64 encoding local function \_b64enc(data) local len = data:len() local t = {} for i=1,len,384 do local n = math.min(384, len+1-i) if n \> 0 then local s = data:sub(i, i+n-1) local enc, \_ = mime.b64(s) t[#t+1] = enc end end return table.concat(t) end encodedPush = \_b64enc(pushMsg) --]] local function networkListener( event ) if ( event.isError ) then print( "Network error!") audio.play( myApp.soundTable["fallAndSplat"] ) local ooopsAlert = native.showAlert( "Ooops", "Push ej skickat, vänligen kontrollera nätverksinställningarna eller försök igen", { "OK" } ) else print ( "RESPONSE: " .. event.response ) audio.play( myApp.soundTable["hahaha"] ) myApp.titleText:morphText( "Ditt medelande är skickat!" , 2000) end end local jsonToSend = {["app\_id"] = "XXXXXXXXXXXX", --["headings"] = {["en"] = fromText}, ["contents"] = {["en"] = finalPush}, ["isAndroid"] = true, ["isIos"] = true, --["included\_segments"] = "All" --["wp\_sound"] = "CartoonHop.wav", ["data"] = {{["abc"] = "123", ["foo"] = "bar"}}, ["tags"] = {{["key"] = "iFreduser", ["relation"] = "=", ["value"] = tillId}}, } loadsave.saveTable(jsonToSend, "send.json") SendJson("https://gamethrive.com/api/v1/notifications", "POST", jsonToSend, networkListener) end

I think the issue might be that you’re wrapping the data value inside an extra set of brackets “{” and “}”

Does it work if you change it to this?

[“data”] = {[“abc”] = “123”, [“foo”] = “bar”},

Yes, no more crashes, thank you =)) And there not being queued on android. On iphone push messages are being received even thou the app in no longer active for a short time, after like anything between 30min to 1 hour the push is not being received even thou the server says that it was, on android the app has to be at least in the background to se push even it it according to the server has been sent to the app. Is this the way its supposed to be? Wouldn’t it better if possible that the push is queued until it is possible for the phone to receive it? I can se in my logs in xcode and logcat that nothing has happened in the background so the pushes are not being rejected.

That’s odd. Is this with iOS 8.1? When the app was no longer active, did you manually close the app from the task switcher?

This is with iOS 8.0.2, been to lazy to update :stuck_out_tongue: Is your second question on iphone or android? On the droid its when I manually closed the app. On the iphone its a bit more random, has happened when my phone has gone to sleep by its self while the app was still running. And sometimes inactive for a longer amount of time, like over the night. But on the last case Im not sure If i have closed the app or not. Let me pay some attention and get back to you.

By manually closing on Android are you doing it with code or by pressing the recent apps button and swiping it close? Also what version of Android and Corona Build are you testing on?

On iOS are you testing with a development(sandbox) or production push certificate? If your internet connection is not stable you might not receive a sandbox notification. From my testing it seems Apple just tries once to send the notification in this environment.

Thanks.

Its by manually closing the app from settings meny on android after existing the app. Its a development certificate on iOS, that could be the issue then =)) Ive now put my phone to always be on 3g with seems to be more stable then the wifi at the moment. Thanks for the info :slight_smile: