RSDTaskState
open class RSDTaskState : NSObject
The task state object is a base class implementation that can upload and archive results, return the encoded result, and manage file cleanup.
-
The result associated with this path component.
Declaration
Swift
public var taskResult: RSDTaskResult
-
Identifier for this task that can be mapped back to a notification. This may be the same as the task identifier, or it might be that a task is scheduled multiple times per day, and the app needs to track what the scheduled timing is for the task.
Declaration
Swift
open var scheduleIdentifier: String?
-
File URL for the directory in which to store generated data files. Asynchronous actions with recorders (and potentially steps) can save data to files during the progress of the task. This property specifies where such data should be written.
If no output directory is specified, this property will use lazy initialization to create a directory in the
NSTemporaryDirectory()
with a subpath of thetaskRunUUID
and the current date.In general, set this property after instantiating the task view controller and before presenting it in order to override the default location.
Before presenting the view controller, set the
outputDirectory
property to specify a path where files should be written when anRSDFileResult
object must be returned for a step.Note
The calling application is responsible for deleting this directory once the files are processed by encrypting them locally. The encrypted files can then be stored for upload to a server or cloud service. These files are not encrypted so depending upon the application, there is a risk of exposing PII data stored in these files.Declaration
Swift
open var outputDirectory: URL! { get set }
-
Create an output directory.
Declaration
Swift
public func createOutputDirectory() -> URL?
Task Finalization - The methods included in this section should **not** be called until the task is finished.
-
A queue that can be used to serialize archiving and cleaning up the file output.
Declaration
Swift
public let fileManagementQueue: DispatchQueue
-
Convenience method for encoding a result. This is a work-around for a limitation of the encoder where it cannot encode an object without a Type for the object.
Declaration
Swift
public func encodeResult(to encoder: RSDFactoryEncoder) throws -> Data
Parameters
encoder
The factory top-level encoder.
Return Value
The encoded result.
-
Cleanup the task following archive and upload.
Declaration
Swift
open func cleanup(error: Error? = nil, completion: ((_ error: Error?) -> Void)? = nil)
-
Delete the output directory on the file management queue. Do not call this method until the files generated by this task have been copied to a new location, unless the results are being discarded.
Declaration
Swift
public func deleteOutputDirectory(error: Error? = nil, completion: ((_ error: Error?) -> Void)? = nil)
-
Build an archive from the task result.
This method will recurse through the task result and pull out data for archiving using the given
RSDDataArchiveManager
to manage vendingRSDDataArchive
instances as appropriate. The completion handler will be called on thefileManagementQueue
so that the app can manage any post-processing that must be serialized as appropriate.This method will call
RSDDataArchive.insertDataIntoArchive()
for eachRSDArchivable
result found in the collection.This method will insert the
RSDTaskResult
as JSON-encoded Data unlessRSDDataArchive.shouldInsertData(for: .taskResult) == false
Finally, it will recursively look through the task result step history and async results for
RSDAnswerResult
objects. The answer results will be added to a consolidated mapping dictionary of answers where the key =\(section.identifier).\(result.identifier)
and the value is thevalue
property. This dictionary will be serialized as JSON-encoded Data.The file results will be added to the files list in a JSON serialized file named
metadata.json
that includes information about the device, application, task, and a file manifest.Declaration
Swift
public func archiveResults(with manager: RSDDataArchiveManager, completion: ((_ error: Error?) -> Void)? = nil)