RSDStepViewController
open class RSDStepViewController : UIViewController, RSDStepController, RSDCancelActionController
RSDStepViewController
is the default base class implementation for the steps presented using this
UI architecture.
-
The stepViewModel presented by the step view controller.
If you use a storyboard to initialize the step view controller,
init(step:parent:)
isn’t called, so you need to set thestepViewModel
property directly before the step view controller is presented.Setting the value of
stepViewModel
after the controller has been presented is an error that generates an assertion. Modifying the value ofstepViewModel
after the controller has been presented is an error that has undefined results.Declaration
Swift
open var stepViewModel: RSDStepViewPathComponent! { get set }
-
Instantiate a step view model appropriate to this step.
Declaration
Swift
open func instantiateStepViewModel(for step: RSDStep, with parent: RSDPathComponent?) -> RSDStepViewPathComponent
-
Convenience property for accessing the step from the step view model.
Declaration
Swift
public var step: RSDStep! { get }
-
Convenience property for casting the step to a
RSDUIStep
.Declaration
Swift
public var uiStep: RSDUIStep? { get }
-
Convenience property for casting the step to a
RSDDesignableUIStep
.Declaration
Swift
public var designableStep: RSDDesignableUIStep? { get }
-
Convenience property for casting the step to a
RSDActiveUIStep
.Declaration
Swift
public var activeStep: RSDActiveUIStep? { get }
-
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 { get set }
-
Returns a new step view controller for the specified step.
Declaration
Swift
public init(step: RSDStep, parent: RSDPathComponent?)
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
inviewDidAppear
before anything else is done. It is set tofalse
inviewWillDisappear
before anything else is done.Declaration
Swift
public private(set) var isVisible: Bool { get }
-
Track whether or not this is the first appearance. This flag is set to
true
inviewDidAppear
. This flag is used to mark whether or not to callperformStartCommands()
.Declaration
Swift
public private(set) var isFirstAppearance: Bool { get }
-
Should this step play an alarm if the phone screen is locked and the app is running in the background? If this is
true
then an alert will run (sound and vibration) until the user opens their phone. The default isfalse
.This is intended for active tasks where the participant needs to look at their phone as soon as possible following a step that was running in the background to alert them to a follow-up action.
Declaration
Swift
open var playAlarmIfBackgrounded: Bool { get }
-
The design system to use with this step view controller.
Declaration
Swift
open var designSystem: RSDDesignSystem!
-
Override
viewWillAppear
to set up the navigation, step details, and background color theme if this is the first appearance.Declaration
Swift
open override func viewWillAppear(_ animated: Bool)
-
Override
viewDidAppear
to set the flag forisVisible
, mark the resultstartDate
, 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 theisVisible
flag and enable the idle timer if it was disabled in view will appear.Declaration
Swift
open override func viewWillDisappear(_ animated: Bool)
-
A mapping of all the buttons that were registered using
setupButton
.Declaration
Swift
public private(set) var registeredButtons: [RSDUIActionType : Set<UIButton>] { get }
-
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: RSDStepNavigationView?
-
A footer view that includes navigation elements.
Declaration
Swift
@IBOutlet open var navigationFooter: RSDNavigationFooterView?
-
A view for the main body.
Declaration
Swift
open var navigationBody: RSDStepNavigationView? { get }
-
The label for displaying step title text.
Declaration
Swift
open var stepTitleLabel: UILabel? { get }
-
The label for displaying step text.
Declaration
Swift
open var stepTextLabel: UILabel? { get }
-
The label for displaying step detail text.
Declaration
Swift
open var stepDetailLabel: UILabel? { get }
-
Convenience method for getting the
Next
button.Declaration
Swift
open var nextButton: UIButton? { get }
-
Convenience method for getting the
Learn More
button.Declaration
Swift
open var learnMoreButton: UIButton? { get }
-
Is forward navigation enabled? The default implementation will check the task controller.
Declaration
Swift
public var isForwardEnabled: Bool { get }
-
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 theRSDThemedUIStep
protocol.Declaration
Swift
open func setupBackgroundColorTheme()
-
Returns the background color tile to use for the given placement. This should look to see if there is color mapping defined by the designable step, then looks to the default if that is undefined.
Declaration
Swift
open func backgroundColor(for placement: RSDColorPlacement) -> RSDColorTile
Parameters
placement
The section of the view to which the color applies.
Return Value
The default color for that placement.
-
Returns the default background color tile to use for the given placement.
Declaration
Swift
open func defaultBackgroundColorTile(for placement: RSDColorPlacement) -> RSDColorTile
Parameters
placement
The section of the view to which the color applies.
Return Value
The default color for that placement.
-
Set the color style for the given placement elements. This allows overriding by subclasses to customize the view style.
Declaration
Swift
open func setColorStyle(for placement: RSDColorPlacement, background: RSDColorTile)
-
The status bar overlay is a view that is set up to be underneath the status bar.
- Default:
If the background uses light style
then the overlay is
clear
elseRSDColor.black.withAlphaComponent(0.1)
If there is a background image then the statusbar background isclear
elsebackground.color
Declaration
Swift
open func setupStatusBar(with background: RSDColorTile)
- Default:
If the background uses light style
then the overlay is
-
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: RSDStepNavigationView)
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, placement: RSDColorPlacement)
Parameters
navigationView
The view to set up.
isFooter
Is this the footer?
-
Return the image theme for this step view controller.
Declaration
Swift
open var imageTheme: RSDImageThemeElement? { get }
-
By default, this method will return
true
if the image theme uses a placement oftopBackground
ortopMarginBackground
.Declaration
Swift
open func hasTopBackgroundImage() -> Bool
-
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?
-
Returns
true
if the given RSDColorPlacement and RSDImagePlacementType indicate that this view controller should set an image,false
otherwise.Declaration
Swift
open func shouldSetNavigationImage(for placement: RSDColorPlacement, with imagePlacement: RSDImagePlacementType) -> Bool
Parameters
placement
the type of RSDColorPlacement that the view is using.
imagePlacement
the type of RSDImagePlacementType that the view is using.
-
Momentarily disable the button. This keeps a double-tap of a navigation button from triggering more than once. This is required b/c of how the UI handles the call to go forward/backward by calling a method that just looks at the current step.
Declaration
Swift
public func momentarilyDisableButton(_ button: UIButton)
-
Navigates forward to the next step. By default, it calls
performStopCommands()
to end the step and speaks theend
instruction. When the end instruction is done, it will callgoForward
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. This method will call
actionTapped(with: .navigation(.skip))
to handle marking the result of the action (if required by the UI) and then will calljumpForward()
.Declaration
Swift
@IBAction open func skipForward()
-
By default, this method calls stop() to stop the timer and then calls
goForward
on the task controller. It is used to handle navigating away from the current step view controller in a manner which requires custom navigation because the step has notended
normally. For example, this method is called when a user taps theskip
button.Declaration
Swift
open func jumpForward()
-
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()
-
Call through to the task view model.
Declaration
Swift
open func shouldConfirmCancel() -> Bool
-
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 anRSDResourceTransformer
and if so, will assume that the learn more is an embedded HTML file or an online URL. It will instantiateRSDWebViewController
and present it modally.Declaration
Swift
@IBAction open func showLearnMore()
-
This method is called when the user taps the
review instructions
button. The default implementation will check if the review action is anRSDNavigationUIAction
and if so, will navigate back to that instruction, setting a value in the async results, marking that abbreviated instructions should not be shown.Declaration
Swift
@IBAction open func showReviewInstructions()
-
Perform any actions associated with a given action type. By default, this is called before any other standard actions on a standard navigation are handled.
Declaration
Swift
open func actionTapped(with actionType: RSDUIActionType) -> Bool
Parameters
actionType
The user-invoked action.
Return Value
true
if the action was handled. If not handled, a default action associated with this action type should be triggered by the calling method. -
Mutate the current result by appending the results with a
skipToIdentifier
.Declaration
Swift
open func assignSkipToIdentifier(_ skipToIdentifier: String)
Parameters
skipToIdentifier
The identifier of the step to go to next.
-
Show an alert to the user to let them know that authorization has failed.
Declaration
Swift
open func handleAuthorizationFailed(status: RSDAuthorizationStatus, permission: RSDStandardPermission)
-
The authorization status for this view controller.
Declaration
Swift
open func checkAuthorizationStatus() -> (status: RSDAuthorizationStatus, permission: RSDStandardPermission?)
-
Check the authorization status for a given permission type.
Declaration
Swift
open func authorizationStatus(for permissionType: RSDStandardPermissionType) -> RSDAuthorizationStatus
-
The permissions required for this step.
Declaration
Swift
open func requiredPermissions() -> [RSDStandardPermission]?
-
The permissions that are requested as a part of this step.
Declaration
Swift
open func requestedPermissions() -> [RSDStandardPermission]?
-
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
-
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 { get }
-
Time interval for firing a repeating timer. Default =
1
.Declaration
Swift
open var timerInterval: TimeInterval { get }
-
The clock 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 var clock: RSDClock?
-
The clock uptime for when the step was finished.
Declaration
Swift
public private(set) var completedUptime: TimeInterval? { get }
-
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 anyRSDActiveUIStepCommand
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)
-
Speak the
end
command (spoken instruction) and then call the completion once finished. If theend
command was previously spoken, then this will call the completion immediately.Declaration
Swift
public func speakEndCommand(_ completion: @escaping (() -> Void))
-
Returns the spoken instruction for a given time point. Default calls the active step spoken instruction.
Declaration
Swift
open func spokenInstruction(at duration: TimeInterval) -> String?
-
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.
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), 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()
-
If the app is running in the background, and running in the background is not allowed for this step, then the app will start calling
playAlert()
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 in order to continue the task. Once the app is active, then it will start the step.Declaration
Swift
open func playAlert()