Has makeWebRequest Ever Surprised You With a Synchronous Callback?

I recently discovered that the callback passed to makeWebRequest - typically named onReceive - can be invoked either synchronously or asynchronously, depending on the situation. In certain error cases, such as error code -104 (indicating no connection to the phone), makeWebRequest calls onReceive immediately, before it even returns to the calling code. In contrast, other errors - such as HTTP status codes or issues with invalid responses - cause onReceive to be called asynchronously, once the response is received.

This behavior can lead to subtle bugs if you assume that any code following the makeWebRequest call will always execute before onReceive. Once you're aware of this, it’s relatively easy to handle, but it’s definitely something to watch out for.

Have you run into similar situations with makeWebRequest?

  • yes i've been there too. since i'm pushing a loading screen view after making a request and switching to another when receiving the response this lead to unexpected ordering of the views on the stack.