|
|
|
//
|
|
|
|
// ViewController.swift
|
|
|
|
// RK-Setup-Cocoa
|
|
|
|
//
|
|
|
|
// Created by Gerardo Marx Chávez Campos on 08/10/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import ResearchKit
|
|
|
|
|
|
|
|
class ViewController: UIViewController {
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func startSurveyTapped(_ sender: UIButton) {
|
|
|
|
// Create a task view controller for the survey
|
|
|
|
let surveyTask = createSurveyTask()
|
|
|
|
let taskViewController = ORKTaskViewController(task: surveyTask, taskRun: nil)
|
|
|
|
taskViewController.delegate = self
|
|
|
|
present(taskViewController, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conform to the ORKTaskViewControllerDelegate protocol
|
|
|
|
extension ViewController: ORKTaskViewControllerDelegate {
|
|
|
|
func taskViewController(
|
|
|
|
_ taskViewController: ORKTaskViewController,
|
|
|
|
didFinishWith reason: ORKTaskViewControllerFinishReason,
|
|
|
|
error: Error?
|
|
|
|
) {
|
|
|
|
// Handle the results of the survey here
|
|
|
|
if reason == .completed {
|
|
|
|
if let results = taskViewController.result.results {
|
|
|
|
for stepResult in results {
|
|
|
|
print("Step: \(stepResult.identifier), Results: \(stepResult)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Dismiss the task view controller
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|