# Run Flows Configured in Dashboard

This integration pattern for the iOS SDK uses the Workflows API. The Workflows API runs onboarding flows defined in Dashboard instead of in your app. It uses modules and configurations you set up in Dashboard, so you don't need to define flows locally by adding `flowConfig` objects to your `IncdOnboardingFlowConfiguration`. You can change a Workflow's configuration in Dashboard without modifying your code.

Unlike the local patterns, where you assemble the flow and configure each module in code, flow content is configured in Dashboard. The modules included in the flow and their settings come from the activated Workflow. Your app only needs to reference it by ID. If you want full control over the flow in client code, see [Configure Flows Locally and Run End to End](https://developer.incode.com/docs/ios-configure-locally-end-to-end). If you need to insert your own screens or logic between SDK modules, see [Configure Flows Locally and Run Step by Step](https://developer.incode.com/docs/ios-configure-flows-locally-and-run-step-by-step). For more information about these patterns, see [Integration Approaches](https://developer.incode.com/docs/ios-flow-configuration).

This page covers session creation and section execution only. Ensure you have followed the steps to [install and initialize](https://developer.incode.com/docs/setup-ios) the Incode iOS SDK first.

For the modules a Workflow can include, see [Modules](https://developer.incode.com/docs/ios-individual-modules). For instructions on configuring Workflows in Dashboard, see [Configure Workflows](https://developer.incode.com/docs/workflows-20).

***

## Set Up This Integration Pattern

Complete the following steps in order.

### Create a Delegate to Receive SDK Results

Conform to `IncdOnboardingDelegate` to receive results from each module and the overall flow. Only `onSuccess()` and `onError(_:)` are required. Every other method has a default empty implementation. Override only the events for the modules your flow includes.

```swift
final class VerificationCoordinator: IncdOnboardingDelegate {

    // MARK: Required

    func onSuccess() {
        // User successfully finished the whole onboarding flow.
    }

    func onError(_ error: IncdFlowError) {
        // Onboarding flow was aborted due to an error.
        print("Flow error: \(error.description)")
    }

    // MARK: Optional (each has a default empty implementation)

    func userCancelledSession() {
        // User backed out of the flow.
    }

    func onOnboardingSessionCreated(_ result: OnboardingSessionResult) {
        // Session created successfully.
    }

    func onAddPhoneNumberCompleted(_ result: PhoneNumberResult) {
        // Phone number step completed.
    }

    func onQRScanCompleted(_ result: QRScanResult) {
        // QR scan completed.
    }

    func onIdFrontCompleted(_ result: IdScanResult) {
        // Front of the ID captured.
    }

    func onIdBackCompleted(_ result: IdScanResult) {
        // Back of the ID captured.
    }

    func onIdProcessed(_ result: IdProcessResult) {
        // ID processing/validation completed.
    }

    func onNFCScanCompleted(_ result: NFCScanResult) {
        // NFC chip read completed.
    }

    func onDocumentScanCompleted(_ result: DocumentScanResult) {
        // Supporting document (for example, proof of address) captured.
    }

    func onSelfieScanCompleted(_ result: SelfieScanResult) {
        // Selfie scan completed.
    }

    func onFaceMatchCompleted(_ result: FaceMatchResult) {
        // Face match completed.
    }

    func onSignatureCollected(_ result: SignatureFormResult) {
        // Signature collected.
    }

    func onUserConsentGiven(_ result: UserConsentResult) {
        // User consent step completed.
    }

    func onVideoSelfieCompleted(_ result: VideoSelfieResult) {
        // Video selfie completed.
    }

    func onCaptchaCompleted(_ result: CaptchaResult) {
        // Captcha step completed.
    }

    func onGeolocationCompleted(_ result: GeolocationResult) {
        // Location captured.
    }

    func onApproveCompleted(_ result: ApprovalResult) {
        // Onboarding approval completed.
    }

    func onUserScoreFetched(_ result: UserScore) {
        // Aggregate results/score fetched.
    }

    func onQueuePositionChanged(_ newQueuePosition: Int) {
        // Position in the Video Conference queue changed.
    }

    func onEstimatedWaitingTime(_ waitingTimeInSeconds: Int) {
        // Estimated Video Conference wait time reported, in seconds.
    }

    func onVideoConferenceCompleted(_ success: Bool, _ error: VideoConferenceError?) {
        // Video Conference call finished.
    }
}
```

The modules in the activated Workflow in Dashboard determine which of these events fire. There is no local `flowConfig` to check instead. For the shape and fields of each result object, see the corresponding page in [Modules](https://developer.incode.com/docs/ios-individual-modules).

### Create the Session Configuration

Dashboard offers two flow types, each with its own entry point:

- **Flow**: Start with `startFlow`.
- **Workflow**: The newer Dashboard-driven orchestration, started with `startWorkflow`. It behaves like a Flow but with different execution logic (branching, conditional steps, retries) maintained in the Dashboard.

Use `IncdOnboardingSessionConfiguration` to specify the session token:

```swift
let session = IncdOnboardingSessionConfiguration(token: "<SESSION_TOKEN>")
```

Reference a specific Dashboard flow by passing its `configurationId` instead of a session token. Ensure the flow is activated in Dashboard before starting the session.

```swift
let session = IncdOnboardingSessionConfiguration(configurationId: "<FLOW_ID>")
```

### Start the Onboarding Session

Start the session using one of the following:

- `startFlow` runs the modules defined for the Flow in Dashboard and reports progress and results through the delegate.

  ```swift
  IncdOnboardingManager.shared.startFlow(sessionConfig: session, delegate: self)
  ```

- `startWorkflow` runs the modules defined for the Workflow in Dashboard and reports progress and results through the delegate.

  ```swift
  IncdOnboardingManager.shared.startWorkflow(sessionConfig: session, delegate: self)
  ```

#### Resume a Partially Completed Flow

Pass `moduleId` to resume a partially completed flow from a specific module:

```swift
public func startFlow(
    sessionConfig: IncdOnboardingSessionConfiguration,
    delegate: IncdOnboardingDelegate?,
    moduleId: String? = nil
)
```

#### Start a Flow from a Universal Link or URL

You can also start a flow from a universal link or URL:

```swift
public func startFlow(url: URL, delegate: IncdOnboardingDelegate?, isShortened: Bool = false)
```

<br />
