[TIMOB-24649] iOS: UI blocked + Network Indicator invisible during synchronous HTTP-Requests with run-on-main-thread
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Resolved |
Resolution | Invalid |
Resolution Date | 2018-03-12T08:58:41.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | n/a |
Reporter | Hans Knöchel |
Assignee | Unknown |
Created | 2017-05-02T16:14:05.000+0000 |
Updated | 2018-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();
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).