Skip to content

Commit 77cc2e0

Browse files
authored
Merge pull request #9 from hansemannn/support-upload
[MOD-2328] Support upload-tasks, move session and configuration to own proxy, major refactoring
2 parents 4f8811c + 9871209 commit 77cc2e0

23 files changed

+772
-522
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: objective-c
2-
osx_image: xcode7.1
2+
osx_image: xcode8.2
33
env:
44
global:
55
- "MODULE_NAME=ti.urlsession"
@@ -8,7 +8,7 @@ before_install:
88
install:
99
- cd $MODULE_ROOT
1010
- curl -o install.sh https://raw.githubusercontent.com/appcelerator-modules/ci/master/travis/install.sh
11-
- source install.sh -s "--branch 5_1_X"
11+
- source install.sh -s "--branch 6_0_X"
1212
script:
1313
- curl -o script.sh https://raw.githubusercontent.com/appcelerator-modules/ci/master/travis/script.sh
1414
- source script.sh
@@ -27,4 +27,4 @@ deploy:
2727
skip_cleanup: true
2828
on:
2929
repo: appcelerator-modules/ti.urlsession
30-
branch: master
30+
branch: master

apidoc/Session.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
name: Modules.URLSession.Session
3+
summary: The session object used to start new tasks.
4+
description: |
5+
These APIs are supported on iOS 7 and later.
6+
7+
The NSURLSession class and related classes provide an API for downloading content.
8+
This API provides a rich set of delegate methods for supporting authentication and gives
9+
your app the ability to perform background downloads when your app is not running or, in iOS,
10+
while your app is suspended.
11+
12+
[iOS Background Services guide](http://docs.appcelerator.com/titanium/latest/#!/guide/iOS_Background_Services).
13+
14+
extends: Titanium.Module
15+
osver: {ios: {min: "7.0"}}
16+
platforms: [iphone, ipad]
17+
since: 6.1.0
18+
19+
methods:
20+
- name: finishTasksAndInvalidate
21+
summary: Invalidates the given session object, allowing any outstanding tasks to finish.
22+
description: |
23+
This method returns immediately without waiting for tasks to finish. Once a session is invalidated,
24+
new tasks cannot be created in the session, but existing tasks continue until completion. Once
25+
invalidated, references to the events and callback objects are broken. Session objects cannot be
26+
reused. To cancel all outstanding tasks, call `invalidateAndCancel` instead.
27+
28+
- name: invalidateAndCancel
29+
summary: Cancels all outstanding tasks and then invalidates the session object.
30+
description: |
31+
Once invalidated, references to the events and callback objects are broken.
32+
Session objects cannot be reused. To allow outstanding tasks to run until
33+
completion, call `finishTasksAndInvalidate` instead.
34+
35+
- name: downloadTask
36+
summary: |
37+
Creates a download task for the specified URL, within the provided session
38+
object and saves the results to a file.
39+
description: |
40+
Once this function is called, the download starts automatically. The progress
41+
of the download can be monitored by listening to the `downloadprogress`,
42+
`downloadcompleted`, `sessioneventscompleted` and `sessioncompleted` events.
43+
parameters:
44+
- name: args
45+
summary: An object representing the arguments to add a new background task.
46+
type: DownloadTaskType
47+
returns:
48+
summary: Task's identifier number.
49+
type: String
50+
51+
- name: uploadTask
52+
summary: |
53+
Creates a upload task for the specified URL, within the provided session
54+
object and local data.
55+
description: |
56+
Once this function is called, the upload starts automatically. The progress
57+
of the upload can be monitored by listening to the `uploadprogress` and
58+
`sessioncompleted` events.
59+
parameters:
60+
- name: args
61+
summary: An object representing the arguments to add a new upload task.
62+
type: UploadTaskType
63+
returns:
64+
summary: Task's identifier number.
65+
type: String
66+
67+
- name: reset
68+
summary: Empties all cookies, cache and credential stores, removes disk files, calls <Modules.URLSession.Session.flush>.
69+
parameters:
70+
- name: callback
71+
summary: Callback to be invoked when the reset completes.
72+
type: Callback
73+
74+
- name: flush
75+
summary: Flushes storage to disk and clear transient network caches.
76+
parameters:
77+
- name: callback
78+
summary: Callback to be invoked when the reset completes.
79+
type: Callback
80+
81+
properties:
82+
- name: configuration
83+
summary: The configuration used for this url session.
84+
description: |
85+
Configuration options for an <Modules.URLSession.Session> object.
86+
When a session is created, a copy of the configuration object is made.
87+
you cannot modify the configuration of a session after it has been created.
88+
89+
The shared session uses the global singleton credential, cache
90+
and cookie storage objects.
91+
92+
An ephemeral session has no persistent disk storage for cookies,
93+
cache or credentials.
94+
95+
A background session can be used to perform networking operations
96+
on behalf of a suspended application, within certain constraints.
97+
optional: false
98+
availability: creation
99+
type: Modules.URLSession.SessionConfiguration
100+
101+
---
102+
name: DownloadTaskType
103+
summary: The parameter for [downloadTask](Modules.URLSession.Session.downloadTask) method.
104+
properties:
105+
- name: url
106+
summary: The remote url used for this data task.
107+
type: String
108+
109+
---
110+
name: UploadTaskType
111+
summary: The parameter for [uploadTask](Modules.URLSession.Session.uploadTask) method.
112+
properties:
113+
- name: url
114+
summary: The remote url used for this data task.
115+
type: String
116+
optional: false
117+
118+
- name: data
119+
summary: The data blob used for this data task.
120+
type: Titanium.Blob
121+
optional: false
122+
123+
- name: method
124+
summary: The request method (e.g. POST or PUT)
125+
default: POST
126+
type: String
127+
128+
- name: requestHeaders
129+
summary: Additional request headers to pass to the request.
130+
type: String

apidoc/SessionConfiguration.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Modules.URLSession.SessionConfiguration
3+
summary: The session configuration object used to create new url sessions.
4+
description: |
5+
These APIs are supported on iOS 7 and later.
6+
7+
An NSURLSessionConfiguration object defines the behavior and policies to use
8+
when uploading and downloading data using an URLSession object. When uploading
9+
or downloading data, creating a configuration object is always the first step
10+
you must take. You use this object to configure the timeout values, caching
11+
policies, connection requirements, and other types of information that you
12+
intend to use with your URLSession object.
13+
14+
[iOS Background Services guide](http://docs.appcelerator.com/titanium/latest/#!/guide/iOS_Background_Services).
15+
16+
extends: Titanium.Module
17+
osver: {ios: {min: "7.0"}}
18+
platforms: [iphone, ipad]
19+
since: 6.1.0
20+
21+
properties:
22+
- name: identifier
23+
summary: The unique identifier for the configuration object.
24+
description: |
25+
This parameter must not be non-null or an empty string.
26+
optional: false
27+
availability: creation
28+
type: String

apidoc/urlsession.yml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,6 @@ excludes:
3434
properties: [bubbleParent]
3535

3636
methods:
37-
- name: createURLSessionBackgroundConfiguration
38-
summary: |
39-
Creates a preconfigured session configuration object that can be used to create a URL session for
40-
performing a background download task.
41-
parameters:
42-
- name: indentifier
43-
summary: Arbitrary string used to identify the session in the events.
44-
type: String
45-
returns:
46-
summary: Configuration object to pass to the <Modules.URLSession.createURLSession> method.
47-
type: Object
48-
49-
- name: createURLSession
50-
summary: Creates a session with the specified session configuration.
51-
description: |
52-
If the session configuration was created with the identifier of a existing session,
53-
then this function would return the pre-existing session.
54-
55-
The session object keeps a strong reference until your app explicitly invalidates the
56-
session. If you do not invalidate the session by calling the `invalidateAndCancel` or
57-
`finishTasksAndInvalidate` method, your app leaks memory.
58-
parameters:
59-
- name: sessionConfiguration
60-
summary: Session configuration object created with the <Modules.URLSession.createURLSessionBackgroundConfiguration>
61-
type: Object
62-
returns:
63-
summary: URL session object.
64-
type: Object
65-
6637
- name: finishTasksAndInvalidate
6738
summary: Invalidates the given session object, allowing any outstanding tasks to finish.
6839
description: |
@@ -74,6 +45,9 @@ methods:
7445
- name: session
7546
summary: URL session object.
7647
type: Object
48+
deprecated:
49+
since: 6.1.0
50+
notes: Use <Modules.URLSession.Session.finishTasksAndInvalidate> (on the session object) instead.
7751

7852
- name: invalidateAndCancel
7953
summary: Cancels all outstanding tasks and then invalidates the session object.
@@ -85,8 +59,14 @@ methods:
8559
- name: session
8660
summary: URL session object.
8761
type: Object
62+
deprecated:
63+
since: 6.1.0
64+
notes: Use <Modules.URLSession.Session.invalidateAndCancel> (on the session object) instead.
8865

8966
- name: backgroundDownloadTaskWithURL
67+
deprecated:
68+
since: 6.1.0
69+
notes: Use <Modules.URLSession.Session.downloadTask> on the session directly.
9070
summary: |
9171
Creates a download task for the specified URL, within the provided session object and saves the
9272
results to a file.
@@ -104,3 +84,23 @@ methods:
10484
returns:
10585
summary: Task's identifier number.
10686
type: String
87+
88+
properties:
89+
- name: configuration
90+
summary: The configuration used for this url session.
91+
description: |
92+
Configuration options for an <Modules.URLSession.Session> object.
93+
When a session is created, a copy of the configuration object is made.
94+
you cannot modify the configuration of a session after it has been created.
95+
96+
The shared session uses the global singleton credential, cache
97+
and cookie storage objects.
98+
99+
An ephemeral session has no persistent disk storage for cookies,
100+
cache or credentials.
101+
102+
A background session can be used to perform networking operations
103+
on behalf of a suspended application, within certain constraints.
104+
optional: false
105+
availability: creation
106+
type: Modules.URLSession.SessionConfiguration

documentation/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## 2.1.0
4+
Add support for upload tasks and more advanced session configuration.
5+
36
## 2.0.0
47
Refactored module to work on iOS 9 and prevent app submission failture. [MOD-2150]
58

documentation/index.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,28 @@ To allow outstanding tasks to run until completion, call finishTasksAndInvalidat
5959

6060
* Takes one argument, a session object : the session which the user wants to invalidate.
6161

62-
### backgroundDownloadTaskWithURL(session object, string)
62+
### addBackgroundDownloadTask(args)
6363

6464
Creates a download task for the specified URL, within the provided session object and saves the results to a file.
6565
Once this function is called, the download starts automatically. The progress of the download can be monitored by listening
6666
to `downloadprogress` , `downloadcompleted`, `sessioneventscompleted` and `sessioncompleted` events explained below.
6767

68-
* Takes two arguments,
69-
* a session object : (Object created using createURLSession()) Session which with the new background task should be associated with.
68+
* Takes an object of arguments,
69+
* session[URLSession] : (Object created using createURLSession()) Session which with the new background task should be associated with.
7070
* url[string] : The string that provides the URL to be downloaded.
71-
71+
72+
73+
### addBackgroundUploadTask(args)
74+
75+
Creates an upload task for the specified URL, within the provided session object and the file-blob to upload.
76+
Once this function is called, the upload starts automatically. The progress of the upload can be monitored by listening
77+
to `uploadprogress` and `sessioncompleted` events explained below.
78+
79+
* Takes an object of arguments,
80+
* session[URLSession] : (Object created using createURLSession()) Session which with the new background task should be associated with.
81+
* url[string] : The string that provides the URL to upload to.
82+
* data[TiBlob] : The file-blob to be uploaded.
83+
7284
Returns the new created task's identifier number.
7385

7486
## Events
@@ -113,7 +125,6 @@ usage :
113125

114126
### sessioncompleted
115127

116-
117128
Informs the app that the task finished transferring data.
118129

119130
<strong>Important</strong>This event is exposed inside Ti.App.iOS Proxy.
@@ -122,8 +133,8 @@ usage :
122133

123134
The following event information will be provided:
124135

125-
* taskIdentifier[int] : The task identifier number for the download task that finished.
126-
* success[boolean] : Indicates if the operation succeeded. Returns true if download succeeded, false otherwise.
136+
* taskIdentifier[int] : The task identifier number for the download or upload task that finished.
137+
* success[boolean] : Indicates if the operation succeeded. Returns true if download or upload succeeded, false otherwise.
127138
* errorCode[int] : The error code of the error, if any (potentially system-dependent).
128139
* message[string] : A string containing the localized description of the error.
129140

@@ -144,5 +155,5 @@ View the [change log](changelog.html) for this module.
144155
Please direct all questions, feedback, and concerns to [info@appcelerator.com](mailto:info@appcelerator.com?subject=iOS%20urlSesson%20Module).
145156

146157
## License
147-
Copyright(c) 2010-2015 by Appcelerator, Inc. All Rights Reserved. Please see the LICENSE
158+
Copyright(c) 2010-Present by Appcelerator, Inc. All Rights Reserved. Please see the LICENSE
148159
file included in the distribution for further details.
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
/**
2-
* ti.urlsession
3-
*
4-
* Created by Your Name
5-
* Copyright (c) 2015 Your Company. All rights reserved.
2+
* Appcelerator Titanium Mobile
3+
* Copyright (c) 2009-Present by Appcelerator, Inc. All Rights Reserved.
4+
* Licensed under the terms of the Apache Public License
5+
* Please see the LICENSE included with this distribution for details.
66
*/
77

88
#import "TiModule.h"
9-
#import "SessionProxy.h"
10-
#import "SessionConfigurationProxy.h"
9+
#import "ComAppceleratorUrlSessionSessionProxy.h"
10+
#import "ComAppceleratorUrlSessionSessionConfigurationProxy.h"
1111
#import <UIKit/UIKit.h>
1212
#import <Foundation/Foundation.h>
1313

1414
@interface ComAppceleratorUrlSessionModule : TiModule {}
1515

16-
-(SessionConfigurationProxy*)createURLSessionBackgroundConfiguration:(id)identifier;
17-
-(SessionProxy*)createURLSession:(id)sessionConfiguration;
18-
-(void)finishTasksAndInvalidate:(SessionProxy*)session;
19-
-(void)invalidateAndCancel:(SessionProxy*)session;
20-
-(NSNumber*)backgroundDownloadTaskWithURL:(id)args;
16+
- (id)createURLSessionBackgroundConfiguration:(id)args; // Deprecated in 2.1.0: Use "createSessionConfiguration" instead.
17+
18+
- (id)createURLSession:(id)args; // Deprecated in 2.1.0: Use "createSession" instead.
19+
20+
- (id)backgroundDownloadTaskWithURL:(id)args; // Deprecated in 2.1.0: Use "addBackgroundDownloadTask" instead.
21+
22+
- (void)finishTasksAndInvalidate:(id)value; // Deprecated in 2.1.0: Use "Session.finishTasksAndInvalidate" instead.
23+
24+
- (void)invalidateAndCancel:(id)value; // Deprecated in 2.1.0: Use "Session.invalidateAndCancel" instead.
25+
26+
- (id)createSessionConfiguration:(id)args;
27+
28+
- (id)createSession:(id)args;
2129

2230
@end

0 commit comments

Comments
 (0)