In using the SDK to transfer files one interacts primarily with the following classes:
Asynchronous interaction with the transfer queue occurs via a class conforming to ASTransferQueueDelegate that is to be provided by the user.
Before any files are transferred the SDK must be initialized:
When creating a session we must provide it with a minimal set of information: an account with host and credentials, a transfer direction and at least one file to transfer:
Since we passed YES to the parameter 'upload:' this session the path added would be interpreted relative to the docroot on the remote machine.
If the very next thing intended for this session is to add it to the queue then there is nothing else to do. If, on the other hand, the session will not be immediately enqueued then it is necessary to manually save it. See Multi-Threaded Environments for more information.
Once a session has been populated, enqueuing it is a simple matter:
The first session is enqueued at index 0, the second at index 1, and so on. Sessions are executed in the same order in which they were enqueued (assuming the queue has been started).
ASTransferQueue contains several different mechanisms for interrupting active sessions in the queue. Each results in an interruption to the transfer but the subsequent behavior of the queue varies. The most common use is to cancel a session (cancelSessionAtIndex: (ASTransferQueue)). Cancelling a session will interrupt the transfer, deactivate it and prevent it from being automatically re-run by the queue again. Cancelled sessions remain in the queue and can be re-run at any time using runSessionAtIndex: (ASTransferQueue).
Another mechanism for interrupting an active session is to run a different session using runSessionAtIndex:. If this method is called with the index of session B while session A is active, the queue will stop session A and start session B. Once session B finishes, session A will resume. Once session A finishes, the queue will continue activating sessions according to their order in the queue.
Two final mechanisms for interrupting active sessions are pausing sessions and stopping sessions. These are less commonly used. Pausing a session will not deactivate it, so it blocks the queue until it is resumed (or otherwise terminates), while stopping a session is much like canceling a session except that the session will be automatically re-run at a later time by the queue. Consult the documentation for pauseSessionAtIndex: (ASTransferQueue) and stopSessionAtIndex: (ASTransferQueue) for more information.
An ASTransferQueue has two modes: stopped and running. A stopped queue is completely passive, while a running queue maintains an active background thread which is responsible for executing any pending transfers. Starting the queue is straightforward:
Normally, the queue may be started when an application is initialized and left running for the entire duration of the application's lifetime (even when that application transitions to and from the background). In some situations, however, it may be desirable to stop the queue. This is equally straightforward:
Both methods return immediately. In the case of stop (ASTransferQueue) the queue will first stop any ongoing session and only then terminate the background thread, thereby transitioning into the stopped state. In general, when next started the queue will pick up the same transfer it had last been transferring (an exception is if the queue had been modified in particular ways while stopped, for instance by adding sessions to the front of the queue)
In order to monitor queue activity - including addition and removal of sessions to the queue and individual session progress - one must implement a queue delegate conforming to ASTransferQueueDelegate.
The queue delegate protocol provides a fair number of delegate methods, each corresponding to different points in session life cycle or general management that may be leveraged to update a UI or otherwise respond to transfer events (but see the warning below the example). It is designed with UITableViews in mind, and all the methods are optional. For the purposes of demonstration only several delegate call implementations are shown here:
Note that for delegate events to be triggered one must first set the queue delegate (see ASTransferQueue::delegate for more information)
Versions 4 and 5 of iOS place restrictions on what types of applications may run in the background, and for how long. By default the Aspera iOS SDK will declare its transfers to the OS as background tasks of finite length, making it so that transfers will continue to run even if the embedding application transitions to the background (this can be disabled if undesirable, see ASTransferQueue::backgroundTaskDemarcationEnabled). These transfers may not complete as iOS does not as of yet allow such tasks to run indefinitely - if they reach the limit allowed to run in the background, all transfers will be stopped.
iOS also provides several other mechanisms for specific types of applications (such as VOIP or location-aware applications) to run in the background. These mechanisms are not leveraged in the SDK, solely that of finite-length background tasks. Furthermore the SDK will not interact or interfere with any other mechanisms used to facilitate running in the background (including other finite-length background tasks).
A session and its associated account are persisted when a session is added to the queue. This means that sessions and accounts, once added, will be around on all future occasions that the application runs - unless they are removed. If at some point in your application's operation it becomes desirable to permanently remove one of these instances this may be done by invoking their respective delete methods:
Removing a session from the queue will delete it, so manually deleting sessions is usually not necessary. Note also that running sessions should not be deleted. Account deletion will fail if there are any existent sessions that reference the account being deleted.
1.8.8