Can a WatchFace Make Several WebRequests?

Former Member
Former Member
I can successfully make one WebRequest using a WatchFace, but I'd like to make *several* WebRequests. Is it possible? Here is what I have tried so far (unsuccessfully):
1) In onTemporalEvent, I made several calls to makeWebRequest specifying the same onRecieve callback.
2) In onTemporalEvent, I made several calls to makeWebRequest specifying *different* onRecieve callbacks.
3) In getServiceDelegate, I returned an array of several ServiceDelegate instances.
  • I've tried that I can extract both in onBackgroundData and get correct data with receivedData[0] and receivedData[1], but how to make them as one JSON object that would be saved into storedData?

  • The way I do this in in onReceive1 and onReceive2, I do

    if(responseCode!=200) { Bg.exit(responseCode);}

    And in onReceive2, do

    Bg.exit([res1,res2]);

    if there isn't an error

    then in onBackgroundData(data)

    if(data instanceof Number) {//got an error}

    else {//got good data}

    if there was an error, you'll likely see null for data when onReceive1 and onReceive2 is called

  • Thanks ... I try to explain me a little better.
    I get the data correctly like you described Bg.exit([res1, res2]);

    The problem is that res1 and res2 are two separate json objects. How do I save them like one (concatenate them) or similar?

    (:background_method)
    function onBackgroundData(data) {
        var pendingWebRequests = getPendingWebRequest();	
    	var type = data.keys()[0]; // Type of received data.
    	var storedData = getProperty(type);
    	var receivedData = data[type]; // The actual data received: strip away type key.
    	
    	var data1 = receivedData[0]; // res1 as JSON object
    	var data2 = receivedData[1]; // res2 as JSON object
    	
    	storedData = HOW TO PUT BOTH JSON OBJECTS HERE;	
    	pendingWebRequests.remove(type);
    	setProperty("PendingWebRequests", pendingWebRequests);
    	setProperty(type, storedData);
    	Ui.requestUpdate();
    	
    }

    HOW TO PUT BOTH JSON OBJECTS HERE - how to store both? ^

  • Technically, data1 and data2 are Monkey C dictionaries which (recursively) contain dictionaries, arrays, numerical types and booleans. (They were JSON objects in the network response, but makeWebRequest() converted them into the corresponding Monkey C types.)

    You can't really concatenate dictionaries (or JSON objects for that matter), but you can put 2 dictionaries in an array (as they already are in your code) and store the array.

    e.g.

    storedData = receivedData;

    However, it looks like you want a solution where you're storing a dictionary. You can achieve that by creating a new dictionary with data1 and data2 as values.

    storedData = {
      :data1 => data1,
      :data2 => data2
    };

    In this example, :data1 and :data2 can be replaced with the symbols of your choice.

  • Thanks!

    that makes sense Muscle tone1

  • You should avoid to call several WebRequests one after the other because strange errors appear. So good solution is paring WebRequests - onRecive, WebRequests - onRecive...