RSDStepViewController

open class RSDStepViewController : UIViewController, RSDStepViewControllerProtocol

RSDStepViewController is the default base class implementation for the steps presented using this UI architecture.

  • Pointer back to the task controller that is displaying the step controller. The implementation of the task controller should set this pointer before displaying the step controller.

    Declaration

    Swift

    open weak var taskController: RSDTaskController!
  • The step view controller delegate.

    Declaration

    Swift

    open weak var delegate: RSDStepViewControllerDelegate?
  • The step presented by the step view controller.

    If you use a storyboard to initialize the step view controller, init(step:) isn’t called, so you need to set the step property directly before the step view controller is presented.

    Setting the value of step after the controller has been presented is an error that generates an assertion. Modifying the value of step after the controller has been presented is an error that has undefined results.

    Subclasses that override the setter of this property must call super.

    Declaration

    Swift

    open var step: RSDStep!
  • Convenience property for casting the step to a RSDUIStep.

    Declaration

    Swift

    public var uiStep: RSDUIStep?
  • Convenience property for casting the step to a RSDThemedUIStep.

    Declaration

    Swift

    public var themedStep: RSDThemedUIStep?
  • Convenience property for casting the step to a RSDActiveUIStep.

    Declaration

    Swift

    public var activeStep: RSDActiveUIStep?
  • Convenience property for accessing the original result after navigating back or from a previous task run.

    Declaration

    Swift

    open var originalResult: RSDResult?
  • Returns the current result associated with this step. This property uses a lazy initializer to instantiate the result and append it to the step history if not found in the step history.

    Declaration

    Swift

    lazy open var currentResult: RSDResult =
  • Returns a new step view controller for the specified step.

    Declaration

    Swift

    public init(step: RSDStep)

    Parameters

    step

    The step to be presented.

  • Initialize the class using the given nib and bundle.

    Declaration

    Swift

    public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)

    Parameters

    nibNameOrNil

    The name of the nib or nil.

    nibBundleOrNil

    The name of the bundle or nil.

  • Required initializer. This is the initializer used by a UIStoryboard.

    Declaration

    Swift

    public required init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    The decoder used to initialize this view controller.

  • Track whether or not the view is visible. The value of this flag is set to true in viewDidAppear before anything else is done. It is set to false in viewWillDisappear before anything else is done.

    Declaration

    Swift

    public private(set) var isVisible = false
  • Track whether or not this is the first appearance. This flag is set to true in viewDidAppear. This flag is used to mark whether or not to call performStartCommands().

    Declaration

    Swift

    public private(set) var isFirstAppearance: Bool = true
  • Override viewWillAppear to call through to the delegate method and if this is the first appearance to set up the navigation, step details, and background color theme.

    Declaration

    Swift

    open override func viewWillAppear(_ animated: Bool)
  • Override viewDidAppear to set the flag for isVisible, call the delegate, mark the result startDate, perform the start commands, and if the active commands include disabling the idle timer then do so in this method.

    Declaration

    Swift

    open override func viewDidAppear(_ animated: Bool)
  • Override viewWillDisappear to set the isVisible flag, call the delegate, and enable the idle timer if it was disabled in view will appear.

    Declaration

    Swift

    open override func viewWillDisappear(_ animated: Bool)
  • Override viewDidDisappear to call the delegate.

    Declaration

    Swift

    open override func viewDidDisappear(_ animated: Bool)
  • A mapping of all the buttons that were registered using setupButton.

    Declaration

    Swift

    public private(set) var registeredButtons: [RSDUIActionType : Set<UIButton>] = [:]
  • A UIView that is behind the status bar. This can be used to set the background for only the top part of a step view.

    Declaration

    Swift

    @IBOutlet open var statusBarBackgroundView: UIView?
  • A header view that includes navigation elements.

    Declaration

    Swift

    @IBOutlet open var navigationHeader: RSDNavigationHeaderView?
  • A footer view that includes navigation elements.

    Declaration

    Swift

    @IBOutlet open var navigationFooter: RSDNavigationFooterView?
  • Convenience method for getting the Next button.

    Declaration

    Swift

    open var nextButton: UIButton?
  • Is forward navigation enabled? The default implementation will check the task controller.

    Declaration

    Swift

    open var isForwardEnabled: Bool
  • Callback from the task controller called on the current step controller when loading is finished and the task is ready to continue.

    Declaration

    Swift

    open func didFinishLoading()
  • Set up the navigation header and footer. Additionally, set up the UI theme colors, UI images, and the step details such as the title, text, detail, and progress.

    Declaration

    Swift

    open func setupViews()
  • Set up the background color using the colorTheme from the step. This method does nothing if the step does not conform to the RSDThemedUIStep protocol.

    Declaration

    Swift

    open func setupBackgroundColorTheme()
  • Set up the header. Because this may be used in a table view as the table’s header view, this includes all the step details that are typically at the top of the view such as setting images, text, and progress. Additionally, this method will set up the navigation buttons included in the header view and any color themes that are appropriate.

    Declaration

    Swift

    open func setupHeader(_ header: RSDNavigationHeaderView)

    Parameters

    header

    The header view.

  • Set up the footer. This method will set up the navigation buttons included in the footer view and any color themes that are appropriate.

    Declaration

    Swift

    open func setupFooter(_ footer: RSDNavigationFooterView)

    Parameters

    footer

    The footer view.

  • Set up the navigation UI elements for the given view. By default, this method will check for whether or not a button should be hidden and set the visibility as is appropriate. For example, the first step in a task should never show a back button. This will also setup color themes, images, selectors, etc.

    Declaration

    Swift

    open func setupNavigationView(_ navigationView: RSDStepNavigationView, isFooter: Bool)

    Parameters

    navigationView

    The view to set up.

    isFooter

    Is this the footer?

  • By default, this method will return true if the image theme uses a placement of topBackground.

    Declaration

    Swift

    open func hasTopBackgroundImage() -> Bool
  • Should the navigation view be set up to use light theme style or dark theme style?

    Declaration

    Swift

    open func usesLightStyle(isFooter: Bool) -> Bool?

    Parameters

    isFooter

    Is this the footer?

    Return Value

    true if this navigation view uses light style.

  • Convenience method for setting up each of the buttons. This will set up color theme, add the selector, and hide the button if indicated by the UI and the task state.

    Declaration

    Swift

    open func setupButton(_ button: UIButton?, for actionType: RSDUIActionType, isFooter: Bool)

    Parameters

    button

    The button to set up.

    actionType

    The navigation action type for the button.

    isFooter

    Is this button in the navigation footer?

  • Navigates forward to the next step. By default, it calls performStopCommands() to end the step and speaks the end instruction. When the end instruction is done, it will call goForward on the task controller.

    When a user taps a Next button, the information passes through this method. You can use this method as an override point or a target action for a subclass.

    Declaration

    Swift

    @IBAction open func goForward()
  • Navigates backward to the previous step. By default, it calls stop() to stop the timer and then calls goBack on the task controller.

    When a user taps the Back button, the information passes through this method. You can use this method as an override point or a target action for a subclass.

    Declaration

    Swift

    @IBAction open func goBack()
  • This method is called when the user taps the skip button. By default, it calls stop() to stop the timer and then calls goForward on the task controller.

    Declaration

    Swift

    @IBAction open func skipForward()
  • This method is called when the user taps the cancel button. By default, it confirms that the task should be canceled (unless this is the first step in the task). If the user confirms exit, then cancelTask is called.

    Declaration

    Swift

    @IBAction open func cancel()
  • Should the step view controller confirm the cancel action? By default, this will return false if this is the first step in the task. Otherwise, this method will return true.

    Declaration

    Swift

    open func shouldConfirmCancel() -> Bool

    Return Value

    Whether or not to confirm the cancel action.

  • Finish canceling the task. This is called once the cancel is confirmed by the user.

    Declaration

    Swift

    open func cancelTask(shouldSave: Bool)

    Parameters

    shouldSave

    Should the task progress be saved?

  • This method is called when the user taps the learn more button. The default implementation will check if the learn more action is an RSDResourceTransformer and if so, will assume that the learn more is an embedded HTML file or an online URL. It will instantiate RSDWebViewController and present it modally.

    Declaration

    Swift

    @IBAction open func showLearnMore()
  • Get the action for the given action type. The default implementation check the step, the delegate and the task as follows:

    • Query the step for an action.
    • If that returns nil, it will then check the delegate.
    • If that returns nil, it will look up the task path chain for an action.
    • Finally, if not found it will return nil.

    Declaration

    Swift

    open func action(for actionType: RSDUIActionType) -> RSDUIAction?

    Parameters

    actionType

    The action type to get.

    Return Value

    The action if found.

  • Should the action be hidden for the given action type?

    • The default implementation will first look to see if the step overrides and forces the action to be hidden.
    • If not, then the delegate will be queried next.
    • If that does not return a value, then the task path will be checked.

    Finally, whether or not to hide the action will be determined based on the action type and the state of the task as follows:

    1. .navigation(.cancel) - Always defaults to false (not hidden).
    2. .navigation(.goForward) - Hidden if the step is an active step that transitions automatically.
    3. .navigation(.goBack) - Hidden if the step is an active step that transitions automatically, or if the task does not allow backward navigation.
    4. Others - Hidden if the action() is nil.

    Declaration

    Swift

    open func shouldHideAction(for actionType: RSDUIActionType) -> Bool

    Parameters

    actionType

    The action type to get.

    Return Value

    true if the action should be hidden.

  • The countdown is a second countdown used by active steps. This value will be 0 if not used. Otherwise, countdown = duration - timeIntervalSinceStart.

    Declaration

    Swift

    open var countdown: Int = 0
  • Should this step start the timer? By default, this will return true for active steps. However, if you are running your app in the background, then you will need to set up a secondary means of keeping the app from suspending when the user locks the screen. You can do so by playing music or by using background GPS location updates.

    Note

    The speech synthesizer does not work when the app is in background mode, but sounds and vibrations will still fire if the AVAudioSession is set up to do so.

    Declaration

    Swift

    open var usesTimer: Bool
  • Time interval for firing a repeating timer. Default = 1.

    Declaration

    Swift

    open var timerInterval: TimeInterval
  • The system uptime for when the step was started. This is used by the timer to determine when to speak the next instruction and to set the value of the countdown.

    Declaration

    Swift

    public private(set) var startUptime: TimeInterval?
  • The system uptime for when the step was paused.

    Declaration

    Swift

    public private(set) var pauseUptime: TimeInterval?
  • The system uptime for when the step was finished.

    Declaration

    Swift

    public private(set) var completedUptime: TimeInterval?
  • Perform any start commands. This will speak an instruction that is set up for the start of the step, set the initial countdown value, and handle any RSDActiveUIStepCommand related to start up including starting the timer if the step should start automatically.

    Declaration

    Swift

    open func performStartCommands()
  • Perform any stop command. This will also call stop() to stop the timer.

    Declaration

    Swift

    open func performStopCommands()
  • Play a sound. The default method will use the shared instance of RSDAudioSoundPlayer.

    Declaration

    Swift

    open func playSound(_ sound: RSDSound = .short_low_high)

    Parameters

    sound

    The sound to play.

  • Vibrate the device (if applicable).

    Declaration

    Swift

    open func vibrateDevice()
  • Speak the given instruction. The default method will use the shared RSDSpeechSynthesizer.

    Declaration

    Swift

    open func speakInstruction(_ instruction: String, at timeInterval: TimeInterval, completion: RSDVoiceBoxCompletionHandler?)

    Parameters

    instruction

    The instruction to speak.

    timeInterval

    The time interval marker (ignored by default implementation).

    completion

    A completion handler to call when the instruction has finished.

  • Speak the instruction that is included at the given time marker (if any).

    Declaration

    Swift

    open func speakInstruction(at duration: TimeInterval)
  • Start the timer.

    Declaration

    Swift

    open func start()
  • Stop the timer.

    Declaration

    Swift

    open func stop()
  • Pause the timer.

    Declaration

    Swift

    open func pause()
  • Resume the timer.

    Declaration

    Swift

    open func resume()
  • Method fired when the timer fires. This method will be called when the timer fires. Should you need to run in the background, you will need to use playing music or GPS updates to keep the app from going to sleep in which case the timer will not fire automatically. Instead, you will need to call this method directly.

    The method will first check to see if the step should be transitioned automatically, based on the uptime and the step duration.

    If the step is completed (countdown == 0), then this method will check if the app is running in the background. If not, it will transition to the next step.

    If the app is running in the background then the app will start calling playCompletedAlert() using dispatch_async with a delay. By default, that method will play an alarm sound and vibrate the device to alert the user to bring the app to the foreground. Once the app is active, then it will transition to the next step.

    If the timer fires and the step is still running, it will check to see if there is a vocal instruction to speak since the last firing of the timer.

    Declaration

    Swift

    open func timerFired()
  • An alert to play if the step should transition automatically and the user has put the app into the background either by locking the screen or else because the system idle timer has fired. This is only called if the app is running in the background. Otherwise, the app will automatically call goForward.

    Declaration

    Swift

    open func playCompletedAlert()