Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24649] iOS: UI blocked + Network Indicator invisible during synchronous HTTP-Requests with run-on-main-thread

GitHub Issuen/a
TypeBug
PriorityNone
StatusResolved
ResolutionInvalid
Resolution Date2018-03-12T08:58:41.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterHans Knöchel
AssigneeUnknown
Created2017-05-02T16:14:05.000+0000
Updated2018-03-12T08:58:41.000+0000

Description

When using run-on-main-thread, synchronous HTTP requests are blocking the UI (and the internal status-bar network activity indicator). Using kroll-thread works fine. Noticed the issue when fixing TIMOB-24648. Test-Case:
var win = Ti.UI.createWindow({
    backgroundColor: '#fff'
});
 
var btn = Ti.UI.createButton({
    title: 'Trigger'
});
 
btn.addEventListener('click', function() {
    var url = "https://httpbin.org/delay/2";
    var client = Ti.Network.createHTTPClient({
        // function called when the response data is available
        onload : function(e) {
            Ti.API.info("Received text: " + this.responseText);
            alert('success');
        },
        // function called when an error occurs, including a timeout
        onerror : function(e) {
            Ti.API.debug(e.error);
            alert('error');
        },
        async: false,
        timeout : 15000  // in milliseconds
    });
    // Prepare the connection.
    client.open("GET", url);
    // Send the request.
    client.send();
});
 
win.add(btn);
win.open();

Comments

  1. Hans Knöchel 2018-03-12

    Considering as a non-issue as sync-requests are supposed to block the UI - asynchronous requests should be used to queue them on background-threads (especially now that we are able to use the NSURLSession APIs). Read more [here](https://stackoverflow.com/a/24548068/5537752).

JSON Source