0

i would like to be able to save and email a pdf of a consent form from research kit. Currently, I have the following code to generate the pdf

let signatureResult : ORKConsentSignatureResult = taskViewController.result.stepResult(forStepIdentifier: "ConsentReviewStep")?.firstResult as! ORKConsentSignatureResult

let consentDocument = ConsentDocument.copy() as! ORKConsentDocument
signatureResult.apply(to: consentDocument)

consentDocument.makePDF { (data, error) -> Void in

    var documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
    documentsPath.append("consent.pef")
    var documentsURL = NSURL.fileURL(withPath: documentsPath)

    try? data?.write(to: documentsURL, options: [.atomic])
}

This first fails with error Terminating app due to uncaught exception 'NSObjectNotAvailableException', reason: 'Signature title is missing'

Not sure where to go from here to get this part working, before moving on to the mailing function.

Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75

1 Answers1

0

For PDF generation, ResearchKit requires that you have a non-nil title property in the ORKConsentSignature object with which you initialize your ORKConsentReviewStep.

Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75