Garmin Connect App crashes when using makeWebRequest ( works fine in the Simulator )

I am using a Garmin Edge 1000 with the latest firmware and an iPhone 6s with the latest OS + Garmin Connect App.

I have written an application the uses OAUTH to connect to a third party web service which works fine and now I am trying to download some data from this third party site.

My code below works as expected on the simulator, but on the actual device when I trigger this request the Garmin Connect App on the iPhone crashes and shuts down, has any else experienced this and does anyone know what might be wrong as there is nothing of use in the log file after this command is triggered.

...
Comm.makeWebRequest(
"api.thirdpartysite.com/search",
{
"location" => long + "," + lat,
"limit" => 6,
"oauth_token" => "USERS TOKEN IS ADDED HERE"
},
{
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
},
method(:onReceiveData)
);
}

// Receive the data from the web request
function onReceiveData(responseCode, data) {
Sys.println("We never reach this point on the device, we do in the simulator...");
}


Any help would be much appreciated, I don't think I am doing anything wrong as it works fine on the simulator but on the device it kills the "Garmin Connect" app on my phone and never returns data to the device.

Cheers,

Chris
  • I have resolved the issue :)

    I have managed to work out why this was not working for me, it seems that I needed the following options to be passed into the makeWebRequest for it to work:

    var headers = {

    // body will be encoded as 'a=1&b=2'
    "Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED,

    // accept responses that are reported as json-compatible
    "Accept" => "application/json"
    };

    var options = {
    :method => Comm.HTTP_REQUEST_METHOD_GET,
    :headers => headers,
    :responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
    };
    I thought I would reply to my own post as it may well help someone else in the future.

    Cheers,

    Chris
  • 6 is an integer

    I had problems with the change to makeWebRequest. I had a specific problem passing an integer in as a parameter and I had to use graphpts.toString() instead of graphpts. So you might find that if 6.toString() is valid that would fix the original code. You might get the same with Lat and long if they are numbers.


    comms.makeWebRequest(url ,{"count"=>graphpts.toString()} ,{"Content-Type"=>comms.REQUEST_CONTENT_TYPE_JSON} ,method(:onGraphReceive));
    worked but

    comms.makeWebRequest(url ,{"count"=>graphpts} ,{"Content-Type"=>comms.REQUEST_CONTENT_TYPE_JSON} ,method(:onGraphReceive));
    did not

    Version 2 of the SDK has a lot of these nasties with things working in the simulator and then not on a watch.

    R.
  • Thanks for the reply and tip,
    Cheers, Chris