123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // ProfileViewController.swift
- // EncuestaMarle
- //
- // Created by Tatiana Castro on 5/21/19.
- // Copyright © 2019 Marle. All rights reserved.
- //
-
- import UIKit
- import ResearchKit
- import PDFKit
-
- class ProfileViewController: UIViewController {
-
- @IBOutlet weak var doneButton: UIButton!
-
- @IBAction func donePressed(_ sender: Any) {
- doneButton.isHidden = true
- doneButton.isEnabled = false
-
- if let viewWithTag = self.view.viewWithTag(1) {
- viewWithTag.removeFromSuperview()
- } else {
- print("error dismissing viewWithTag!")
- }
- }
-
- @IBAction func see_consent(_ sender: Any) {
-
- var docURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last as NSURL?
- docURL = docURL?.appendingPathComponent("ConsentDocument.pdf") as NSURL?
- print(docURL as Any)
- // let webView = WKWebView(frame: UIScreen.main.bounds)
- // webView.tag = 1
- // view.addSubview(webView)
- // webView.navigationDelegate = (self as? WKNavigationDelegate)
- //
- // webView.load(URLRequest(url: docURL! as URL))
- //
- let pdfView = PDFView()
- pdfView.translatesAutoresizingMaskIntoConstraints = false
- view.addSubview(pdfView)
- pdfView.tag = 1
- pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
- pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
- pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
- pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
-
- // guard let path = Bundle.main.url(forResource: "test", withExtension: "pdf") else { return }
-
- if let document = PDFDocument(url: docURL! as URL) {
- pdfView.document = document
- }
-
- doneButton.isHidden = false
- doneButton.isEnabled = true
-
- func removeWebView() {
- pdfView.removeFromSuperview()
- }
- // func removeWebView() {
- // webView.removeFromSuperview()
- // }
-
- // func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {
- // switch reason {
- // case .completed:
- // let result = task.result
- // if let stepResult = result.stepResultForStepIdentifier("ConsentReviewStep"),
- // let signatureResult = stepResult.results?.first as? ORKConsentSignatureResult {
- // signatureResult.applyToDocument(consentDocument)
- //
- // consentDocument.makePDF { (data, error) -> Void in
- // let tempPath = NSTemporaryDirectory() as NSString
- // let path = tempPath.appendingPathComponent("signature.pdf")
- // data?.writeToFile(path, atomically: true)
- // print(path)
- // }
- //
- // }
- //
- // default:
- // break
- // }
- // }
- }
-
- // func taskViewController(_ taskViewController: ORKTaskViewController?, didFinishWith reason: ORKTaskViewControllerFinishReason) throws {
- // switch reason {
- // case ORKTaskViewControllerFinishReasonCompleted:
- // var signatureResult = task.result.stepResult(forStepIdentifier: "consentReviewIdentifier").firstResult() as? ORKConsentSignatureResult
- // if signatureResult?.signature.signatureImage != nil {
- // signatureResult?.signature.title = "\(signatureResult?.signature.givenName ?? "") \(signatureResult?.signature.familyName ?? "")"
- // signatureResult?.apply(toDocument: consentDocument)
- //
- // consentDocument.makePDF(withCompletionHandler: { pdfFile, error in
- // var paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
- // var filePath = URL(fileURLWithPath: paths[0]).appendingPathComponent("Consent.pdf").absoluteString
- // try? pdfFile?.write(toFile: filePath, options: .atomic)
- // })
- // }
- // default:
- // break
- // }
- // }
- override func viewDidLoad() {
- super.viewDidLoad()
-
- doneButton.isHidden = true
- doneButton.isEnabled = false
-
- // Do any additional setup after loading the view.
- }
-
-
- /*
- // MARK: - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
-
- }
|