Geen omschrijving

ProfileViewController.swift 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // ProfileViewController.swift
  3. // EncuestaMarle
  4. //
  5. // Created by Tatiana Castro on 5/21/19.
  6. // Copyright © 2019 Marle. All rights reserved.
  7. //
  8. import UIKit
  9. import ResearchKit
  10. import PDFKit
  11. class ProfileViewController: UIViewController {
  12. @IBOutlet weak var doneButton: UIButton!
  13. @IBAction func donePressed(_ sender: Any) {
  14. doneButton.isHidden = true
  15. doneButton.isEnabled = false
  16. if let viewWithTag = self.view.viewWithTag(1) {
  17. viewWithTag.removeFromSuperview()
  18. } else {
  19. print("error dismissing viewWithTag!")
  20. }
  21. }
  22. @IBAction func see_consent(_ sender: Any) {
  23. var docURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last as NSURL?
  24. docURL = docURL?.appendingPathComponent("ConsentDocument.pdf") as NSURL?
  25. print(docURL as Any)
  26. // let webView = WKWebView(frame: UIScreen.main.bounds)
  27. // webView.tag = 1
  28. // view.addSubview(webView)
  29. // webView.navigationDelegate = (self as? WKNavigationDelegate)
  30. //
  31. // webView.load(URLRequest(url: docURL! as URL))
  32. //
  33. let pdfView = PDFView()
  34. pdfView.translatesAutoresizingMaskIntoConstraints = false
  35. view.addSubview(pdfView)
  36. pdfView.tag = 1
  37. pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
  38. pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
  39. pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
  40. pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
  41. // guard let path = Bundle.main.url(forResource: "test", withExtension: "pdf") else { return }
  42. if let document = PDFDocument(url: docURL! as URL) {
  43. pdfView.document = document
  44. }
  45. doneButton.isHidden = false
  46. doneButton.isEnabled = true
  47. func removeWebView() {
  48. pdfView.removeFromSuperview()
  49. }
  50. // func removeWebView() {
  51. // webView.removeFromSuperview()
  52. // }
  53. // func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {
  54. // switch reason {
  55. // case .completed:
  56. // let result = task.result
  57. // if let stepResult = result.stepResultForStepIdentifier("ConsentReviewStep"),
  58. // let signatureResult = stepResult.results?.first as? ORKConsentSignatureResult {
  59. // signatureResult.applyToDocument(consentDocument)
  60. //
  61. // consentDocument.makePDF { (data, error) -> Void in
  62. // let tempPath = NSTemporaryDirectory() as NSString
  63. // let path = tempPath.appendingPathComponent("signature.pdf")
  64. // data?.writeToFile(path, atomically: true)
  65. // print(path)
  66. // }
  67. //
  68. // }
  69. //
  70. // default:
  71. // break
  72. // }
  73. // }
  74. }
  75. // func taskViewController(_ taskViewController: ORKTaskViewController?, didFinishWith reason: ORKTaskViewControllerFinishReason) throws {
  76. // switch reason {
  77. // case ORKTaskViewControllerFinishReasonCompleted:
  78. // var signatureResult = task.result.stepResult(forStepIdentifier: "consentReviewIdentifier").firstResult() as? ORKConsentSignatureResult
  79. // if signatureResult?.signature.signatureImage != nil {
  80. // signatureResult?.signature.title = "\(signatureResult?.signature.givenName ?? "") \(signatureResult?.signature.familyName ?? "")"
  81. // signatureResult?.apply(toDocument: consentDocument)
  82. //
  83. // consentDocument.makePDF(withCompletionHandler: { pdfFile, error in
  84. // var paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
  85. // var filePath = URL(fileURLWithPath: paths[0]).appendingPathComponent("Consent.pdf").absoluteString
  86. // try? pdfFile?.write(toFile: filePath, options: .atomic)
  87. // })
  88. // }
  89. // default:
  90. // break
  91. // }
  92. // }
  93. override func viewDidLoad() {
  94. super.viewDidLoad()
  95. doneButton.isHidden = true
  96. doneButton.isEnabled = false
  97. // Do any additional setup after loading the view.
  98. }
  99. /*
  100. // MARK: - Navigation
  101. // In a storyboard-based application, you will often want to do a little preparation before navigation
  102. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  103. // Get the new view controller using segue.destination.
  104. // Pass the selected object to the new view controller.
  105. }
  106. */
  107. }