Hi,
My widget is not working (broken IQ icon) after trying to display data from webRequest. Everything works fine on the simulator. Watch is connected to phone (and internet), there are permissions for communication. What might be the problem?
Thanks!
class appView extends Ui.View {
hidden var _message;
var myData = 0;
function initialize(message) {
View.initialize();
}
// Load your resources here
function onLayout(dc) {
setLayout(Rez.Layouts.MainLayout(dc));
}
function onShow() {
makeRequest();
}
function onUpdate(dc) {
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
System.println( "myData: " + myData );
dc.clear();
dc.setColor(Gfx.COLOR_LT_GRAY, Gfx.COLOR_TRANSPARENT);
dc.drawText(120, 100,Gfx.FONT_TINY, myData, Gfx.TEXT_JUSTIFY_CENTER);
}
function onHide() {
}
// set up the response callback function
function onReceive(responseCode, data) {
if (responseCode == 200) {
System.println("data size: " + data.size());
if(data.size() > 0) {
myData = data[0];
}
} else {
System.println("Response: " + responseCode);
}
WatchUi.requestUpdate();
}
function makeRequest() {
var url = "https://some.domain.com";
var options = {
:method => Communications.HTTP_REQUEST_METHOD_GET,
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
var responseCallback = method(:onReceive);
Communications.makeWebRequest(url, options, {}, method(:onReceive));
}
}