我当前正在创建一个想要利用ResearchKit的程序。在进入调查问题之前,我需要征得同意。我正在使用Ray Wenderlich(https://www.raywenderlich.com/1820-researchkit-tutorial-with-swift-getting-started)教程并已设置此代码。我已经尝试过进行程序的调查部分,并且甚至无需经过同意就可以访问它。

import ResearchKit

public var ConsentTask: ORKOrderedTask {

    var ctr = 0

    let Document = ORKConsentDocument()
    Document.title = "Consent"

    //section types
    let sectionTypes: [ORKConsentSectionType] = [
        .overview,
        .dataGathering,
        .privacy
    ]

    let consentSections: [ORKConsentSection] = sectionTypes.map { contentSectionType in
        let consentSection = ORKConsentSection(type: contentSectionType)

        if ctr < sectionTypes.count {

            if ctr == 0 {
                consentSection.summary = "Summary"
                consentSection.content = "Content"
            }

            else if ctr == 1 { //Data Gathering
                consentSection.summary = "Summary"
                consentSection.content = "Content"
            }

            else if ctr == 2 { //Privacy
                consentSection.summary = "Summary"
                consentSection.content = "Content"
            }

            ctr = ctr + 1
        }
        return consentSection
    }

    Document.sections = consentSections
    Document.addSignature(ORKConsentSignature(forPersonWithTitle: nil, dateFormatString: nil, identifier: "UserSignature"))

    var steps = [ORKStep]()

    let visualConsentStep = ORKVisualConsentStep(identifier: "VisualConsent", document: Document)
    steps += [visualConsentStep]

    let signature = Document.signatures!.first! as ORKConsentSignature
    let reviewConsentStep = ORKConsentReviewStep(identifier: "Review", signature: signature, in: Document)
    reviewConsentStep.text = "Review the consent"
    reviewConsentStep.reasonForConsent = "I agree"

    steps += [reviewConsentStep]

    //Completion
    let completionStep = ORKCompletionStep(identifier: "CompletionStep")
    completionStep.title = "Welcome"
    completionStep.text = "Thank you for helping!"
    steps += [completionStep]

    return ORKOrderedTask(identifier: "ConsentTask", steps: steps)
}


在我的视图控制器中,

    @IBAction func consentTask(_ sender: Any) {

    if consentDone == false {
        let taskViewController = ORKTaskViewController(task: ConsentTask, taskRun: nil)
        taskViewController.delegate = self
        present(taskViewController, animated: true, completion: nil)
    }
    else if consentDone == true {
        //would they like to leave the study

    }
}


经过我的努力,在此处放置了acceptdone标志。

    func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {

    taskViewController.dismiss(animated: true, completion: {() in self.consentDone = true})
    print(consentDone)

}


但是,发生的情况是,如果用户按下右上角的“取消”或在同意书的最后按“完成”,它将始终触发此操作。有没有一种方法可以确保仅在所有步骤完成后才执行代码块?理想情况下,在此之后,我希望将此标记标记为用户已完成同意。之后,我每次都会将用户重定向到其他页面,直到用户离开研究。

最佳答案

经过反复试验,我在这里找到了答案:https://github.com/ResearchKit/ResearchKit/issues/919

通过知道用户的签名意味着用户已完成表格,我们可以

  if result.identifier == "UserSignature"{
      print(result)
      let consentDoneAnswerResult = result as! ORKConsentSignatureResult
      let consentDone = consentDoneAnswerResult.consented
      print(consentDone)
  }


这样,在完成表单时,而不是将其取消,同意的确为true。

09-25 22:12