I'm trying to get web requests going starting the the JsonTransaction example and i keep getting an error complaining about the callback method not being valid. I'm api level 3.3.0 any thought on why the simulator doesnt like this callback method?
import Toybox.System; import Toybox.Communications; import Toybox.Lang; class JsonTransaction { // set up the response callback function function onReceive(responseCode as Number, data as Dictionary) as Void { if (responseCode == 200) { System.println("Request Successful"); // print success } else { System.println("Response: " + responseCode); // print response code } } function makeRequest() as Void { var url = "https://www.garmin.com"; // set the url var params = { // set the parameters "definedParams" => "123456789abcdefg" }; var options = { // set the options :method => Communications.HTTP_REQUEST_METHOD_GET, // set HTTP method :headers => { // set headers "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED}, // set response type :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED }; var responseCallback = method(:onReceive); // set responseCallback to // onReceive() method // Make the Communications.makeWebRequest() call Communications.makeWebRequest(url, params, options, responseCallback); } }
error
ERROR: edge530: /Users/savan/workspaces/edge-garmin/Edge/source/JsonTransaction.mc:33,8: Invalid '$.Toybox.Lang.Method(responseCode as $.Toybox.Lang.Number, data as $.Toybox.Lang.Dictionary) as Void' passed as parameter 4 of type 'PolyType<(callback(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String) as Void) or (callback(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String, context as $.Toybox.Lang.Object) as Void)>'.