RSDTaskController

public protocol RSDTaskController : class, NSObjectProtocol

RSDTaskController handles default implementations for running a task.

To start a task, create an instance of a view controller that conforms to this protocol and set either the topLevelTask or the topLevelTaskInfo.

  • A mutable path object used to track the current state of a running task.

    Declaration

    Swift

    var taskPath: RSDTaskPath!
  • Optional factory subclass that can be used to vend custom steps that are decoded from a plist or json.

    Declaration

    Swift

    var factory: RSDFactory?
  • Can the task progress be saved? This should only return true if the task result can be saved and the current progress can be restored.

    Declaration

    Swift

    var canSaveTaskProgress: Bool
  • Returns the currently active step controller (if any).

    Declaration

    Swift

    var currentStepController: RSDStepController?
  • Returns a list of the async action controllers that are currently active. This includes controllers that are requesting permissions, starting, running, and stopping.

    Declaration

    Swift

    var currentAsyncControllers: [RSDAsyncActionController]
  • Should the protocol extension fetch the subtask from a task info object or does this implementation handle subtask step navigation using custom logic?

    Declaration

    Swift

    func shouldFetchSubtask(for step: RSDTaskInfoStep) -> Bool

    Parameters

    step

    The RSDTaskStep for which to fetch the task.

    Return Value

    true if the task should be fetched using the protocol extension.

  • Should the protocol extension vend the steps in a section using paging to move to the next step or does this implementation handle section steps using custom logic?

    Declaration

    Swift

    func shouldPageSectionSteps(for step: RSDSectionStep) -> Bool

    Parameters

    step

    The RSDSectionStep for which show the paged steps.

    Return Value

    true if the protocol extension should handle paging the steps.

  • Show a loading state while fetching the given task from the task info.

    Declaration

    Swift

    func showLoading(for taskInfo: RSDTaskInfoStep)

    Parameters

    taskInfo

    The task info for the task being fetched.

  • Fired when the task controller is ready to go forward. This method must invoke the goForward() method either to go forward automatically or else go forward after a user action.

    Declaration

    Swift

    func handleFinishedLoading()
  • Hide the loading state if currently showing it.

    Declaration

    Swift

    func hideLoadingIfNeeded()
  • Navigate to the next step from the previous step in the given direction.

    Declaration

    Swift

    func navigate(to step: RSDStep, from previousStep: RSDStep?, direction: RSDStepDirection, completion: ((Bool) -> Void)?)

    Parameters

    step

    The step to show.

    previousStep

    The previous step. This is either the step currently being displayed or else the RSDSectionStep or RSDTaskStep if the previous step was the last step in a paged section or fetched subtask.

    direction

    The direction in which to show the animation change.

    completion

    The completion to call once the navigation animation has completed.

  • Failed to fetch the task from the current task path. Handle the error. A retry can be fired by calling goForward().

    Declaration

    Swift

    func handleTaskFailure(with error: Error)

    Parameters

    error

    The error returned by the failed task fetch.

  • The task has completed, either as a result of all the steps being completed or because of an early exit.

    Declaration

    Swift

    func handleTaskCompleted()
  • This method is called when a task result is ready for upload, save, archive, etc. This method will be called when either (a) the task is ready to dismiss or (b) when the task is displaying the last completion step.

    Declaration

    Swift

    func handleTaskResultReady(with taskPath: RSDTaskPath)
  • The user has tapped the cancel button.

    Declaration

    Swift

    func handleTaskCancelled(shouldSave: Bool)

    Parameters

    shouldSave

    Should the task progress be saved (if applicable).

  • Add async action controllers to the shared queue for the given configuations. It is up to the task controller to decide how to create the controllers and how to manage adding them to the currentStepController array.

    The async actions should not be started. Instead they should be returned with idle status.

    Note

    If creating the recorder might take time, the task controller should move creation to a background thread so that the main thread is not blocked.

    Declaration

    Swift

    func addAsyncActions(with configurations: [RSDAsyncActionConfiguration], completion: @escaping (([RSDAsyncActionController]) -> Void))

    Parameters

    configurations

    The configurations to start.

    completion

    The completion to call with the instantiated controllers.

  • Start the async action controllers. The protocol extension calls this method when an async action should be started directly after the step is presented.

    The task controller needs to handle blocking any navigation changes until the async controllers are ready to proceed. Otherwise, the modal popup alert can be swallowed by the step change.

    Declaration

    Swift

    func startAsyncActions(for controllers: [RSDAsyncActionController], showLoading: Bool, completion: @escaping (() -> Void))
  • Stop the async action controllers. The protocol extension does not directly implement stopping the async actions to allow customization of how the results are added to the task and whether or not forward navigation should be blocked until the completion handler is called. When the stop action is called, the view controller needs to handle stopping the controllers, adding the results, and showing a loading state until ready to move forward in the task navigation.

    Declaration

    Swift

    func stopAsyncActions(for controllers: [RSDAsyncActionController], showLoading: Bool, completion: @escaping (() -> Void))
  • topLevelTaskInfo Extension method

    Convenience method for getting/setting the main entry point for the task controller via the task info.

    Declaration

    Swift

    public var topLevelTaskInfo : RSDTaskInfoStep!
  • topLevelTask Extension method

    Convenience property for getting/setting the main entry point for the task controller via the task.

    Declaration

    Swift

    public var topLevelTask : RSDTask!
  • taskResult Extension method

    Convenience property for getting the result for this task.

    Declaration

    Swift

    public var taskResult : RSDTaskResult!
  • topLevelTaskPath Extension method

    Convenience property for getting the top level task path.

    Declaration

    Swift

    public var topLevelTaskPath : RSDTaskPath!
  • startTaskIfNeeded() Extension method

    Start the task if it is not currently loaded with a task or first step.

    Declaration

    Swift

    public func startTaskIfNeeded()
  • isForwardEnabled Extension method

    Can this task go forward? If forward navigation is disabled, then the task isn’t waiting for a result or a task fetch to enable forward navigation.

    Declaration

    Swift

    public var isForwardEnabled: Bool
  • hasStepAfter Extension method

    Is there a next step or is this the last step in the task?

    Declaration

    Swift

    public var hasStepAfter: Bool
  • hasStepBefore Extension method

    Is there previous step that this task can go back to?

    Declaration

    Swift

    public var hasStepBefore: Bool
  • goForward() Extension method

    Go forward to the next step. If the task is not loaded for the current point in the task path, then it will attempt to fetch it again.

    Note

    This method will throw an assertion if it is called without first checking that the current task can navigate forward.

    Declaration

    Swift

    public func goForward()
  • goBack() Extension method

    Go back to the previous step.

    Note

    This method will throw an assertion if there isn’t a previous step.

    Declaration

    Swift

    public func goBack()