Skip to content

Commit f0851f3

Browse files
committed
Bump to 2.2.0, actually start task
1 parent fbfb65a commit f0851f3

File tree

3 files changed

+55
-34
lines changed

3 files changed

+55
-34
lines changed

apidoc/Session.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,27 @@ methods:
5959
parameters:
6060
- name: args
6161
summary: An object representing the arguments to add a new upload task.
62-
type: UploadTaskType
62+
type: UploadDataTaskType
63+
returns:
64+
summary: Task's identifier number.
65+
type: String
66+
67+
- name: dataTask
68+
summary: |
69+
Creates a data task for the specified URL, within the provided session
70+
object and local data.
71+
description: |
72+
An data task does not provide any additional functionality over a usual
73+
session task and its presence is merely to provide lexical differentiation
74+
from download and upload tasks.
75+
76+
Once this function is called, the task starts automatically. Once finished,
77+
the data task will call the `sessioncompleted` event containing infos about
78+
the response.
79+
parameters:
80+
- name: args
81+
summary: An object representing the arguments to add a new task task.
82+
type: UploadDataTaskType
6383
returns:
6484
summary: Task's identifier number.
6585
type: String
@@ -107,7 +127,7 @@ properties:
107127
type: String
108128

109129
---
110-
name: UploadTaskType
130+
name: UploadDataTaskType
111131
summary: The parameter for [uploadTask](Modules.URLSession.Session.uploadTask) method.
112132
properties:
113133
- name: url

ios/Classes/ComAppceleratorUrlSessionSessionProxy.m

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ - (id)dataTask:(id)args
112112
{
113113
ENSURE_SINGLE_ARG(args, NSDictionary);
114114

115-
NSURLSessionUploadTask *task = nil;
116115
NSString *url = nil;
117116
NSString *method = nil;
118117
NSDictionary *headers = nil;
@@ -122,41 +121,43 @@ - (id)dataTask:(id)args
122121
ENSURE_ARG_OR_NIL_FOR_KEY(method, args, @"method", NSString);
123122
ENSURE_ARG_OR_NIL_FOR_KEY(headers, args, @"requestHeaders", NSDictionary);
124123

125-
if ([url length] != 0) {
126-
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[TiUtils toURL:url proxy:self]];
127-
128-
// HTTP method
129-
[request setHTTPMethod:(method ?: @"POST")];
130-
131-
// Optional request headers
132-
if (headers) {
133-
for (id key in headers) {
134-
ENSURE_TYPE(key, NSString);
135-
ENSURE_TYPE([headers objectForKey:key], NSString);
136-
137-
[request setValue:[headers objectForKey:key] forHTTPHeaderField:key];
138-
}
139-
}
140-
141-
if (data != nil) {
142-
NSError *error = nil;
143-
NSData *postData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&error];
124+
NSURL *nativeURL = [TiUtils toURL:url proxy:self];
125+
126+
if (nativeURL == nil) {
127+
NSLog(@"[ERROR] Ti.URLSession: The specified URL for this data task is empty. Please provide a valid URL.");
128+
return nil;
129+
}
130+
131+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nativeURL];
132+
133+
// HTTP method
134+
[request setHTTPMethod:(method ?: @"POST")];
135+
136+
// Optional request headers
137+
if (headers) {
138+
for (id key in headers) {
139+
ENSURE_TYPE(key, NSString);
140+
ENSURE_TYPE([headers objectForKey:key], NSString);
144141

145-
if (error == nil) {
146-
[request setHTTPBody:postData];
147-
} else {
148-
DebugLog(@"[ERROR] Could not append data: %@", error.localizedDescription);
149-
}
142+
[request setValue:[headers objectForKey:key] forHTTPHeaderField:key];
150143
}
151-
152-
NSURLSessionDataTask *task = [_session dataTaskWithRequest:request];
144+
}
145+
146+
if (data != nil) {
147+
NSError *error = nil;
148+
NSData *postData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&error];
153149

154-
return NUMINTEGER([task taskIdentifier]);
155-
} else {
156-
NSLog(@"[ERROR] Ti.URLSession: The specified URL for this data task is empty. Please provide a valid URL.");
150+
if (error == nil) {
151+
[request setHTTPBody:postData];
152+
} else {
153+
DebugLog(@"[ERROR] Could not append data: %@", error.localizedDescription);
154+
}
157155
}
156+
157+
NSURLSessionDataTask *task = [_session dataTaskWithRequest:request];
158+
[task resume];
158159

159-
return nil;
160+
return NUMINTEGER([task taskIdentifier]);
160161
}
161162

162163
- (void)finishTasksAndInvalidate:(id)unused

ios/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# this is your module manifest and used by Titanium
33
# during compilation, packaging, distribution, etc.
44
#
5-
version: 2.1.0
5+
version: 2.2.0
66
apiversion: 2
77
architectures: armv7 arm64 i386 x86_64
88
description: ti.urlsession

0 commit comments

Comments
 (0)