BLE_CONNECTION_UNAVAILABLE error when making HTTP request in View.initialize()

Within my View initialize function I am calling

Comm.registerForPhoneAppMessages( method(:phoneMessageCallback) );

Within the phoneMessageCallback function I am making image request 

Comm.makeImageRequest

If there are messages waiting to be processed when the view is initialized the image request will return BLE_CONNECTION_UNAVAILABLE = -104.  If messages arrive after the view has been initialized, those message are processed successfully.

Is bluetooth not available in the View initialize function? If this isn't the correct place to registerForPhoneAppMessages, where is the correct place to do it?

  • registerForPhoneAppMessages  is something for companion apps on the phone and not needed if you are doing makeImageRequests or makeWebRequests.

    But doing this in your initialize shouldn't be an issue.

    The error you're seeing is that at the point you're trying to use the phone to communicate, the phone isn't connected - you're out of range or it just hasn't connected yet after you turned on the watch. 

  • Correct, I have a companion application that has sent messages to my connect iq widget while it is not running. The messages are in the mailbox till the widget is initialized. When I invoke the widget, the messages are processed and I get the BLE_CONNECTION_UNAVAILABLE = -104 when I try to make an image request in my phoneMessageCallback callback method. If I send a new message to the widget while it is running, the message is processed successfully and a image request succeeds.

  • Sound like you're dealing with different points in time, and when you try to do the makeImageRequest, you're no longer connected, and are getting an error to indicate that.  Not much that can be done for that, except maybe check the phone connection before you process the messages so nothing happens until there is a connection.