{ "id": "133769", "key": "TIMOB-17403", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2014-07-26T00:14:23.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [], "versions": [ { "id": "15422", "description": "Release 3.3.0", "name": "Release 3.3.0", "archived": false, "released": true, "releaseDate": "2014-07-16" } ], "issuelinks": [], "assignee": null, "updated": "2018-02-28T20:04:15.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "The final {{ondatastream}} event containing progress=1 is fired after the DONE {{onreadystatechange}} event. This means you fall into a wonky state where the request is finished but you haven't been notified that all of the data has been received.\r\n\r\n{code}\r\nvar xhr = Ti.Network.createHTTPClient();\r\nxhr.setTimeout(6e4);\r\nvar dataStreamFinished = false;\r\nxhr.onreadystatechange = function(e) {\r\n\tTi.API.info('state = ' + this.readyState + ' (' + dataStreamFinished + ')');\r\n\tif (this.readyState == this.DONE && dataStreamFinished) finish();\r\n};\r\nxhr.ondatastream = function(e) {\r\n\tif (!e.progress) callback_error(\"Errors in ondatastream\");\r\n\tTi.API.info(e.progress);\r\n\tif (e.progress >= .9) dataStreamFinished = true;\r\n};\r\nxhr.onerror = function(e) {\r\n\tcallback_error(e);\r\n};\r\nxhr.open(\"GET\", \"http://www.appcelerator.com/assets/The_iPad_App_Wave.pdf\");\r\nxhr.send();\r\n{code}\r\n\r\nApparently, this is how the events are dispatched in native land.\r\n\r\nTo resolve this issue, when the DONE {{onreadystatechange}} event is fired, disconnect the {{ondatastream}} event handler, manually fire the {{ondatastream}} event with progress=1, then continue to fire the DONE {{onreadystatechange}} event.", "attachment": [], "flagged": false, "summary": "iOS: final ondatastream event should be fired before final onreadystatechange event", "creator": { "name": "cbarber", "key": "cbarber", "displayName": "Chris Barber", "active": true, "timeZone": "America/Chicago" }, "subtasks": [], "reporter": { "name": "cbarber", "key": "cbarber", "displayName": "Chris Barber", "active": true, "timeZone": "America/Chicago" }, "environment": null, "comment": { "comments": [ { "id": "389821", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Correct me if I am wrong, but I guess we could just swap the lines in [here|https://github.com/appcelerator/APSHTTPClient/blob/master/APSHTTPClient/APSHTTPRequest.m#L537] and it should fit your expectations - which I share.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-07-02T05:51:29.000+0000", "updated": "2016-07-02T05:51:29.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }