You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB
Swift

2 months ago
//
// ViewController.swift
// RK-Setup-Cocoa
//
// Created by Gerardo Marx Chávez Campos on 08/10/24.
//
import UIKit
2 months ago
import ResearchKit
2 months ago
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
2 months ago
@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)
}
}
2 months ago
2 months ago
// 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)
}
2 months ago
}