Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2379] Ti.URLSession module: expose dataTask equivalent API which is available in native iOS.

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2018-02-01T20:15:00.000+0000
Affected Version/sn/a
Fix Version/sTi.URLSession 2.2.0
ComponentsUrlSession
Labelsn/a
ReporterJebun Naher
AssigneeHans Knöchel
Created2017-12-12T06:45:05.000+0000
Updated2018-08-06T17:49:36.000+0000

Description

This is an Enterprise customer requirement. The original scenario is as below: We have a requirement where we need to upload a document to the service along with some data like document ID , document Name, document Category. When we have gone through the ti.URLSession module we have seen the methods like uploadTask where we are only able to pass the input as blob/image but not the additional information as mentioned above. In the native iOS implementation we have seen the methods like dataTask and did not find the equivalent API call in Titanium module. Can you please provide a solution for this scenario or can expose the equivalent API to dataTask which is available in native iOS.

Comments

  1. Hans Knöchel 2017-12-13

    I've done a [pull request](https://github.com/appcelerator-modules/ti.urlsession/pull/13) to support this last week. Does it resolve the request? If not, what additional API's should be exposed?
  2. Shuo Liang 2017-12-22

    [~hknoechel] It PR looks good to me. Will forward customer the pre-release see if it fits customer's request.
  3. Mostafizur Rahman 2018-01-22

    [~hknoechel] Is there any update here?
  4. Hans Knöchel 2018-02-01

    Just merged the PR and did some additional changes, so the sessioncompleted event actually gets called. The new release (2.2.0) can be found on the [Github page](https://github.com/appcelerator-modules/ti.urlsession/releases/tag/v2.2.0). Full example:
       var URLSession = require('com.appcelerator.urlSession');
       
       var sessionConfig = URLSession.createSessionConfiguration({
         identifier: 'com.test.test2'
       });
       
       var session = URLSession.createSession({
         configuration: sessionConfig
       });
       
       var window = Ti.UI.createWindow({
         backgroundColor: 'white',
         title: 'Ti.URLSession'
       });
       
       var nav = Ti.UI.iOS.createNavigationWindow({
         window: window
       });
       
       var triggerButton = Titanium.UI.createButton({
         title: 'Start Data Task'
       });
       
       triggerButton.addEventListener('click', function() {
       
         var taskIdentifier = session.dataTask({
           url: 'http://some-url.io',
           type: "POST",
           requestHeaders: {
             'Content-Type': 'application/json'
           },
           data: {
             id: 123,
             category: "category-456"
           }
         });
       
         Ti.API.info('Starting data task with task identifier: ' + taskIdentifier);
       });
       
       window.add(triggerButton);
       nav.open();
       
       // Called when the data task completes
       Ti.App.iOS.addEventListener('sessioncompleted', function(event) {
         alert('Session completed');
         Ti.API.info(JSON.stringify(event));
       });
       
  5. Eric Merriman 2018-08-06

    Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.

JSON Source