Skip to content
ForstaMobileApp edited this page Sep 9, 2022 · 1 revision

NOTE: The SDK must first be initialized, see Initializing the SDK

Android

// - Your Forsta Plus server
val serverId = ConfirmitServer.UK.serverId

// - Your Digital Feedback program key
val programKey = "<Program Key>"

// - Proceed download - Kotlin Coroutine
// The SDK also provides synchronous call: TriggerSDK.download()
val result = TriggerSDK.downloadAsync(serverId, programKey).await()

if(result.result) {
    // Your Digital Feedback program is started!
} else {
    // Digital Feedback program download failed
    // Tip: a possible reason is that your program contains scripting errors
}

// NOTE: SDK also provides synchronous method
TriggerSDK.download(serverId, programKey)
class MyMainFragment : Fragment(), ProgramCallback {

    // My app fragment implementation ...

    // ProgramCallback implementation starts

    override fun onWebSurveyStart(fragment: SurveyWebViewFragment) {
        val activity = this.requireActivity()
        fragment.setCallback(MySurveyCallback())
        fragment.show(activity.supportFragmentManager, "SurveyWebViewFragment")
    }

    override fun onSurveyStart(config: SurveyFrameConfig) {
        // This is used when implement survey with native UI
        // For implementation detail, please check "Native UI Survey Integration" section
    }

    override fun onAppFeedback(triggerInfo: TriggerInfo, data: Map<String, String?>) {
        // When AppFeedback action triggered
    }

    override fun onScenarioError(triggerInfo: TriggerInfo, exception: Exception) {
        // When scenario scripting contains error
    }

    override fun onScenarioLoad(triggerInfo: TriggerInfo, exception: Exception?) {
        // On scenario script starts
    }

    override fun onSurveyDownloadCompleted(triggerInfo: TriggerInfo, surveyId: String, exception: Exception?) {
        // Survey download completed
    }

    private class MySurveyCallback() : SurveyWebViewFragmentCallback {
        override fun onWebViewSurveyError(serverId: String, projectId: String, exception: Exception) {
            // When WebView fails to process web survey
        }

        override fun onWebViewSurveyFinished(serverId: String, projectId: String) {
            // When survey is completed
        }

        override fun onWebViewSurveyQuit(serverId: String, projectId: String) {
            // When survey is quit / canceled
        }
    }
}

iOS

// - Your Forsta Plus server
let serverId = ConfirmitServer.uk.serverId

// - Your Digital Feedback program key
let programKey = "<Program Key>"

// - Proceed download
TriggerSDK.download(serverId: serverId, programKey: programKey) { (result, error) in
    if result {
        // Your Digital Feedback program is started!
    } else {
        // Digital Feedback program download failed
        // Tip: a possible reason is that your program contains scripting errors
    }
}
class MyMainController: UIViewController, ProgramCallback {
  // My app controller implementation ...

  // ProgramCallback implementation starts

  func onWebSurveyStart(surveyWebView: SurveyWebViewController) {
    surveyWebView.delegate = self
    present(surveyWebView, animated: true)
  }

  func onSurveyStart(config: SurveyFrameConfig) {
    // This is used when implement survey with native UI
    // For implementation detail, please check "Native UI Survey Integration" section
  }

  func onSurveyDownloadCompleted(triggerInfo: TriggerInfo, surveyId: String, error: Error?) {
    // Survey download completed
  }

  func onScenarioLoad(triggerInfo: TriggerInfo, error: Error?) {
    // On scenario script starts
  }

  func onScenarioError(triggerInfo: TriggerInfo, error: Error) {
    // When scenario scripting contains error
  }

  func onAppFeedback(triggerInfo: TriggerInfo, data: [String: String?]) {
    // When AppFeedback action triggered
  }
}

extension MyMainController: SurveyWebViewControllerDelegate {
  func onWebViewSurveyError(serverId: String, projectId: String, error: Error) {
    // When WebView fails to process web survey
  }

  func onWebViewSurveyFinished(serverId: String, projectId: String) {
    // When survey is completed
  }

  func onWebViewSurveyQuit(serverId: String, projectId: String) {
    // When survey is quit / canceled
  }
}

Clone this wiki locally