[TIMOB-19540] iOS: Ti.Network.HTTPClient does not work in synchronous mode in SDK 3.3.0+
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-01-25T11:48:08.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.0.2 |
Components | iOS |
Labels | regression |
Reporter | Paul R. King |
Assignee | Hans Knöchel |
Created | 2014-10-02T23:47:11.000+0000 |
Updated | 2017-01-25T11:48:13.000+0000 |
Description
I took the exact code that is in the documentation for Titanium.Network.HTTPClient and it works fine as it is for all environments. I took the sample code and modified it by making the open() call synchronous ([async = false] for 3rd parameter) and it fails in SDK 3.3.0 and 3.4.0. Normally I would not use synchronous mode, however, I inherited a large project that relies on a synchronous call and it fails. The code below is the sample code with the one parameter modified. You can stick this anywhere in a simple project and you should be able to see the problem. Neither onload() or onerror() are called in SDK 3.3.0, but they are in SDK 3.2.3. I've tried on Xcode 5 and 6 and iOS 7 and 8, with the same results. It clearly seems to be a regression in SDK 3.3.0.
var url = "http://www.appcelerator.com";
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');
},
timeout : 5000 // in milliseconds
});
// Prepare the connection.
// BUG:
// This code is the sample code from the documentation simply added to the doClick function above.
// The only change is to add the 3rd paramater [async] which defaults to 'true'.
// When it is 'true', everything works fine, but when set to 'false', neither the onload() or onerror()
// functions are called. This code works with SDK 3.2.3, but not with SDK 3.3.0 or 3.4.0.
client.open("GET", url, false);
// Calling with async set to true succeeds
//client.open("GET", url, true);
// Send the request.
client.send();
PR: https://github.com/appcelerator/APSHTTPClient/pull/38 Will update the SDK after the PR has been approved.
CR and FT passed! Update SDK please :)
PR (titanium_mobile/master): https://github.com/appcelerator/titanium_mobile/pull/8542
PR merged!
Verified the fix with this environment: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.12.1 Appc CLI: 6.0.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.1.0.v20161121004950 Appcelerator Studio, build: 4.8.0.201611121409 Xcode 8.1 GM I first tried the demo app on SDK 6.0.0 with iOS 10.1.1 device, and found that when the app loaded, there was no activity, and the 5000 ms timeout error did not occur. I then tried it with SDK 6.1.0, and an alert popped up with "Success", as expected. The bug is considered fixed.
Reopening to add release version for back-port
PR (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8768
Validated with this environment: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.12.1 Appc CLI: 6.1.0 Appc CLI NPM: 4.2.8 Titanium SDK version: 6.0.2.v20170123062940 Appcelerator Studio, build: 4.8.1.201612050850 Xcode 8.2 iOS Device: 10 I tried the demo app on SDK 6.0.1 with iOS 10.1.1 device, and found that when the app loaded, there was no activity, and the 5000 ms timeout error did not occur (when it should have) After reproducing this bug, I then tried it with SDK 6.0.2, and an alert popped up with "Success", as expected.