Keine Beschreibung

OnboardingViewController.swift 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. //
  2. // OnboardingViewController.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. var jsonDict_reg = [String: Any]()
  11. var n_jsonDict_reg = [String: Any]()
  12. var jsonDict_r = [String: Any]()
  13. var n_jsonDict_r = [String: Any]()
  14. var jsonString_reg = String()
  15. var jsonString_r = String()
  16. var jsonData_reg = Data()
  17. var newResponseReg: Bool = false
  18. var response_reg: String = "" {
  19. didSet {
  20. newResponseReg = true
  21. }
  22. }
  23. var newResponseR: Bool = false
  24. var response_r: String = "" {
  25. didSet {
  26. newResponseR = true
  27. }
  28. }
  29. var task = ORKTaskViewController()
  30. var consentDocument = ConsentDocument()
  31. var task_def = String()
  32. var sentPDF: Bool = false
  33. var jsonPDF = String()
  34. var response_PDF = String()
  35. var tokenPDF = String()
  36. var resetPassword: Bool = false
  37. var jsonString_reset = String()
  38. var jsonDict_reset = [String: Any]()
  39. var n_jsonDict_reset = [String: Any]()
  40. var response_reset = String()
  41. func getConsent_task(task: ORKTaskViewController) -> ORKTaskViewController{
  42. return task
  43. }
  44. func limpiarJson_reg(){
  45. let resultados_encuestas = jsonDict_reg["results"] as! [[String:Any]]
  46. if let resultado_pregunta = resultados_encuestas[2]["results"] as? [[String:Any]]{
  47. n_jsonDict_reg["token"]=token
  48. tokenPDF = token
  49. n_jsonDict_reg["email"]=resultado_pregunta[0]["textAnswer"]
  50. n_jsonDict_reg["password"]=resultado_pregunta[1]["textAnswer"]
  51. n_jsonDict_reg["gender"]=resultado_pregunta[3]["choiceAnswers"]
  52. // -------------------------------------------- ☹️ ----------------------------------------------
  53. // Removed due to Apple screwing up the keyboard constraints
  54. n_jsonDict_reg["job"]=resultado_pregunta[4]["choiceAnswers"]
  55. let date = resultado_pregunta[5]["dateAnswer"] as! String
  56. n_jsonDict_reg["yearBirth"]=date.prefix(4)
  57. }
  58. }
  59. func limpiarJson_recovery(){
  60. let resultados_encuestas = jsonDict_r["results"] as! [[String:Any]]
  61. if let resultado_pregunta = resultados_encuestas[0]["results"] as? [[String:Any]]{
  62. n_jsonDict_r["token"]=token
  63. n_jsonDict_r["email"]=resultado_pregunta[0]["textAnswer"]
  64. n_jsonDict_r["password"]=resultado_pregunta[1]["textAnswer"]
  65. }
  66. }
  67. //func limpiarJson_reset(){
  68. // let resultados_encuestas = jsonDict_reset["results"] as! [[String:Any]]
  69. // if let resultado_pregunta = resultados_encuestas[0]["results"] as? [[String:Any]]{
  70. // n_jsonDict_reset["email"]=resultado_pregunta[0]["textAnswer"]
  71. // }
  72. //}
  73. func sendEmail(email: String) {
  74. //impiarJson_reset()
  75. let jsonObject: NSMutableDictionary = NSMutableDictionary()
  76. jsonObject.setValue(email, forKey: "email")
  77. let request = NSMutableURLRequest(url: NSURL(string: "http://tania.uprrp.edu/askForEmail.php")! as URL)
  78. request.httpMethod = "POST"
  79. let jsonData: NSData
  80. do {
  81. jsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: JSONSerialization.WritingOptions()) as NSData
  82. let jsonEmail = NSString(data: jsonData as Data, encoding: String.Encoding.utf8.rawValue) as! String
  83. print("✅ Email recieved, sending request...")
  84. let postString = "data=\(jsonEmail)"
  85. request.httpBody = postString.data(using: String.Encoding.utf8)
  86. let task = URLSession.shared.dataTask(with: request as URLRequest) {
  87. data, response, error in
  88. if error != nil {
  89. print("error=\(String(describing: error))")
  90. return
  91. }
  92. print("response solito Email = \(String(describing: response))") //Error: 1062
  93. let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
  94. print("responseString Email = \(String(describing: responseString))")
  95. response_reset = responseString as! String
  96. }
  97. task.resume()
  98. } catch {
  99. print ("❌ JSON Failure")
  100. }
  101. }
  102. func sendJson_reg() {
  103. let request = NSMutableURLRequest(url: NSURL(string: "http://tania.uprrp.edu/registration.php")! as URL)
  104. request.httpMethod = "POST"
  105. let postString = "data=\(jsonString_reg)"
  106. print("json Sign-Up ✅")
  107. request.httpBody = postString.data(using: String.Encoding.utf8)
  108. let task = URLSession.shared.dataTask(with: request as URLRequest) {
  109. data, response, error in
  110. if error != nil {
  111. print("error=\(String(describing: error))")
  112. return
  113. }
  114. print("response solito Sign Up = \(String(describing: response))") //Error: 1062
  115. let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
  116. print("responseString Sign Up = \(String(describing: responseString))")
  117. response_reg = responseString! as String
  118. }
  119. task.resume()
  120. }
  121. func sendJson_r() {
  122. limpiarJson_recovery()
  123. do {
  124. let jsonData_r = try JSONSerialization.data(withJSONObject: n_jsonDict_r, options: .prettyPrinted)
  125. jsonString_r = NSString(data: jsonData_r, encoding: String.Encoding.utf8.rawValue)! as String
  126. }
  127. catch {
  128. print(error.localizedDescription)
  129. }
  130. let request = NSMutableURLRequest(url: NSURL(string: "http://tania.uprrp.edu/recoverAccount.php")! as URL)
  131. request.httpMethod = "POST"
  132. let postString = "data=\(jsonString_r)"
  133. request.httpBody = postString.data(using: String.Encoding.utf8)
  134. let task = URLSession.shared.dataTask(with: request as URLRequest) {
  135. data, response, error in
  136. if error != nil {
  137. print("error=\(String(describing: error))")
  138. return
  139. }
  140. print("response Recover Account ⚠️ solito = \(String(describing: response))") //Error: 1062
  141. let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
  142. print("response Recover Account ⚠️ reg= \(String(describing: responseString))")
  143. response_r = responseString as! String
  144. // REMEMBER TO PRESENT ERRORS BASED ON RESPONSE (EMAIL MAL OR PW MAL)
  145. }
  146. task.resume()
  147. }
  148. func sendPDF(_ base64EncodedPDF: String, _ date: Date) {
  149. if sentPDF == false {
  150. let request = NSMutableURLRequest(url: NSURL(string: "http://tania.uprrp.edu/getSignatureIOS2.php")! as URL)
  151. request.httpMethod = "POST"
  152. // let jsonObject1: [String: Any] = [
  153. // "data": [
  154. // "signaturePDFBase64": base64EncodedPDF,
  155. // "signatureDate": date,
  156. // "token": tokenPDF
  157. // ],
  158. // ]
  159. let jsonObject: NSMutableDictionary = NSMutableDictionary()
  160. jsonObject.setValue(base64EncodedPDF, forKey: "signaturePDFBase64")
  161. jsonObject.setValue(date.description, forKey: "signatureDate")
  162. jsonObject.setValue(tokenPDF, forKey: "token")
  163. print("Date is formatted as: 📆")
  164. print(date.description)
  165. let jsonData: NSData
  166. do {
  167. jsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: JSONSerialization.WritingOptions()) as NSData
  168. let jsonString_PDF = NSString(data: jsonData as Data, encoding: String.Encoding.utf8.rawValue) as! String
  169. print("✅ jsonPDF Created, sending request...")
  170. let postString = "data=\(jsonString_PDF)"
  171. request.httpBody = postString.data(using: String.Encoding.utf8)
  172. let task = URLSession.shared.dataTask(with: request as URLRequest) {
  173. data, response, error in
  174. if error != nil {
  175. print("error=\(String(describing: error))")
  176. return
  177. }
  178. print("response solito PDF = \(String(describing: response))") //Error: 1062
  179. let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
  180. print("responseString PDF = \(String(describing: responseString))")
  181. response_PDF = responseString as! String
  182. }
  183. sentPDF = true
  184. task.resume()
  185. } catch {
  186. print ("❌ JSON Failure")
  187. }
  188. }
  189. }
  190. class OnboardingViewController: UIViewController {
  191. @IBAction func joinButtonTapped(_ sender: UIButton) {
  192. let consentStep = ORKVisualConsentStep(identifier: "VisualConsentStep", document: consentDocument)
  193. let registrationTitle = NSLocalizedString("Registration", comment: "")
  194. let passcodeValidationRegularExpressionPattern = "^(?=.*\\d).{4,8}$"
  195. let passcodeValidationRegularExpression = try! NSRegularExpression(pattern: passcodeValidationRegularExpressionPattern)
  196. let passcodeInvalidMessage = NSLocalizedString("A valid password must be 4 to 8 characters long and include at least one numeric character.", comment: "")
  197. let registrationOptions: ORKRegistrationStepOption = [.includeGender, .includeJob, .includeDOB]
  198. let registrationStep = ORKRegistrationStep(identifier: "registration", title: registrationTitle, text: "Register for MARLE Study", passcodeValidationRegularExpression: passcodeValidationRegularExpression, passcodeInvalidMessage: passcodeInvalidMessage, options: registrationOptions)
  199. let signature = consentDocument.signatures!.first!
  200. let reviewConsentStep = ORKConsentReviewStep(identifier: "ConsentReviewStep", signature: signature, in: consentDocument)
  201. reviewConsentStep.text = "Review the consent form."
  202. reviewConsentStep.reasonForConsent = "Consent to join the MARLE Study."
  203. let passcodeStep = ORKPasscodeStep(identifier: "Passcode")
  204. passcodeStep.text = "Now you will create a passcode to identify yourself to the app and protect access to information you've entered."
  205. let completionStep = ORKCompletionStep(identifier: "CompletionStep")
  206. completionStep.title = "Welcome aboard."
  207. completionStep.text = "Thank you for joining this study."
  208. print("checko")
  209. task_def = "registration"
  210. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep])
  211. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  212. taskViewController.delegate = self
  213. if response_reg == "Error:Email"{
  214. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep])
  215. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  216. taskViewController.delegate = self
  217. present(taskViewController, animated: true){
  218. let alertTitle = NSLocalizedString("Error: Email Already Registered", comment: "")
  219. let alertMessage = NSLocalizedString("Exit and try recovering your account", comment: "")
  220. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  221. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  222. taskViewController.present(alert, animated: true, completion: nil)
  223. self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  224. }
  225. }
  226. else if response_reg == "Error:Token"{
  227. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep])
  228. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  229. taskViewController.delegate = self
  230. present(taskViewController, animated: true){
  231. let alertTitle = NSLocalizedString("Error: Phone Already Used", comment: "")
  232. let alertMessage = NSLocalizedString("This phone has been used to create an account already. Please contact your mentor.", comment: "")
  233. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  234. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  235. taskViewController.present(alert, animated: true, completion: nil)
  236. self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  237. }
  238. }
  239. else{
  240. let c_orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep, completionStep])
  241. let c_taskViewController = ORKTaskViewController(task: c_orderedTask, taskRun: nil)
  242. c_taskViewController.delegate = self
  243. present(c_taskViewController, animated: true, completion: nil)
  244. let taskViewController = ORKTaskViewController(task: EncuestaMarle, taskRun: nil)
  245. taskViewController.delegate = (self as ORKTaskViewControllerDelegate)
  246. present(taskViewController, animated: true, completion: nil)
  247. }
  248. }
  249. @IBAction func recover_account(_ sender: UIButton) {
  250. class LoginViewController : ORKLoginStepViewController {
  251. override func forgotPasswordButtonTapped() {
  252. var email: String = ""
  253. let alertTitle = NSLocalizedString("Enter your email", comment: "")
  254. let alertMessage = NSLocalizedString("You will recieve instructions to reset your password.", comment: "")
  255. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  256. alert.addTextField { (textField) in
  257. textField.placeholder = "Email"
  258. }
  259. alert.addAction(UIAlertAction(title: "Submit", style: UIAlertAction.Style.default, handler: { [weak alert] (_) in
  260. let textField = alert!.textFields![0] // Force unwrapping because we know it exists.
  261. print("Text field email: \(String(describing: textField.text))")
  262. email = textField.text!
  263. sendEmail(email: email)
  264. let alertTitle2 = NSLocalizedString("If the email is registered we will send you an email", comment: "")
  265. let alertMessage2 = NSLocalizedString("Check \(email) for instructions to reset your password", comment: "")
  266. let alert2 = UIAlertController(title: alertTitle2, message: alertMessage2, preferredStyle: UIAlertController.Style.alert)
  267. alert2.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  268. self.present(alert2, animated: true, completion: nil)
  269. }))
  270. alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel , handler: nil))
  271. self.present(alert, animated: true, completion: nil)
  272. }
  273. }
  274. let loginTitle = NSLocalizedString("Recover Account", comment: "")
  275. let loginStep = ORKLoginStep(identifier: "recover" , title: loginTitle, text: "Fill out information to recover account", loginViewControllerClass: LoginViewController.self)
  276. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [loginStep])
  277. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  278. taskViewController.delegate = self
  279. if (resetPassword) {
  280. task_def = "reset"
  281. resetPassword = false
  282. let alertTitle2 = NSLocalizedString("Email will arrive soon", comment: "")
  283. let alertMessage2 = NSLocalizedString("Check your inbox for instructions to reset your password", comment: "")
  284. let alert2 = UIAlertController(title: alertTitle2, message: alertMessage2, preferredStyle: UIAlertController.Style.alert)
  285. alert2.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  286. self.present(alert2, animated: true, completion: nil)
  287. }
  288. else {
  289. task_def = "recover"
  290. }
  291. present(taskViewController, animated: true, completion: nil)
  292. }
  293. }
  294. extension OnboardingViewController : ORKTaskViewControllerDelegate {
  295. public func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
  296. switch reason {
  297. case .completed:
  298. if task_def == "reset" {
  299. let taskResult_reset = taskViewController.result
  300. let jsonData_reset = try! ORKESerializer.jsonData(for: taskResult_reset)
  301. jsonString_reset = NSString(data: jsonData_reset, encoding: String.Encoding.utf8.rawValue)! as String
  302. jsonDict_reset = convertToDictionary(text: jsonString_r as String) as! [String: Any]
  303. do {
  304. let jsonData_reset = try JSONSerialization.data(withJSONObject: jsonDict_reset, options: .prettyPrinted)
  305. jsonString_reset = NSString(data: jsonData_reset, encoding: String.Encoding.utf8.rawValue)! as String
  306. }
  307. catch {
  308. print(error.localizedDescription)
  309. }
  310. //sendEmail()
  311. }
  312. else if task_def == "recover"{
  313. let taskResult_r = taskViewController.result
  314. let jsonData_r = try! ORKESerializer.jsonData(for: taskResult_r)
  315. jsonString_r = NSString(data: jsonData_r, encoding: String.Encoding.utf8.rawValue)! as String
  316. jsonDict_r = convertToDictionary(text: jsonString_r as String) as! [String: Any]
  317. do {
  318. let jsonData_r = try JSONSerialization.data(withJSONObject: jsonDict_r, options: .prettyPrinted)
  319. jsonString_r = NSString(data: jsonData_r, encoding: String.Encoding.utf8.rawValue)! as String
  320. }
  321. catch {
  322. print(error.localizedDescription)
  323. }
  324. sendJson_r()
  325. // TODO:
  326. // THIS REPRESENTS HOW TO RESPOND TO WRONG INPUT
  327. while(newResponseR == false) {}
  328. newResponseR = false
  329. // implement if (resetPassword == true) workflow
  330. if (response_r == "Error:hash" || response_r == "Error:password") {
  331. let alertTitle = NSLocalizedString("Email and Password do not match", comment: "")
  332. let alertMessage = NSLocalizedString("Try again or tap forgot password.", comment: "")
  333. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  334. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  335. taskViewController.present(alert, animated: true, completion: nil)
  336. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  337. }
  338. else if response_r == "Error:token"{
  339. let alertTitle = NSLocalizedString("Phone already registered", comment: "")
  340. let alertMessage = NSLocalizedString("This phone has been used to create an account already. Please contact your mentor and inform them about this error message", comment: "")
  341. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  342. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  343. taskViewController.present(alert, animated: true, completion: nil)
  344. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  345. }
  346. else {
  347. UserDefaults.standard.set(true, forKey: "registered")
  348. UserDefaults.standard.synchronize()
  349. performSegue(withIdentifier: "unwindToStudy", sender: nil)
  350. }
  351. }
  352. else{
  353. let taskResult_reg = taskViewController.result
  354. if let stepResult = taskResult_reg.stepResult(forStepIdentifier: "ConsentReviewStep"),
  355. let signatureResult = stepResult.results?.first as? ORKConsentSignatureResult {
  356. print("Signature generated ✅")
  357. print(signatureResult)
  358. let signatureDate = signatureResult.endDate
  359. // lets try to make a pdf for this
  360. let documentCopy = consentDocument
  361. signatureResult.apply(to: documentCopy)
  362. documentCopy.makePDF { (data, error) -> Void in
  363. var docURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last as NSURL?
  364. docURL = docURL?.appendingPathComponent("ConsentDocument.pdf") as NSURL?
  365. do {
  366. try data?.write(to:docURL! as URL)
  367. print("PDF generated ✅")
  368. print(docURL! as URL)
  369. if let pdfBase64 = data?.base64EncodedString() {
  370. sendPDF(pdfBase64, signatureDate)
  371. }
  372. } catch let error {
  373. print("❌")
  374. print(error.localizedDescription)
  375. }
  376. }
  377. // let sigJson = try! ORKESerializer.jsonData(for: signatureResult)
  378. // print(sigJson.base64EncodedString())
  379. }
  380. let jsonData_reg = try! ORKESerializer.jsonData(for: taskResult_reg)
  381. jsonString_reg = NSString(data: jsonData_reg, encoding: String.Encoding.utf8.rawValue)! as String
  382. jsonDict_reg = convertToDictionary(text: jsonString_reg as String) as! [String: Any]
  383. limpiarJson_reg()
  384. do {
  385. let jsonData_reg = try JSONSerialization.data(withJSONObject: n_jsonDict_reg, options: .prettyPrinted)
  386. jsonString_reg = NSString(data: jsonData_reg, encoding: String.Encoding.utf8.rawValue)! as String
  387. }
  388. catch {
  389. print(error.localizedDescription)
  390. }
  391. // TODO:
  392. // MAYBE THIS DOES IT BETTER
  393. sendJson_reg()
  394. while(newResponseReg == false) {}
  395. newResponseReg = false
  396. if response_reg == "Error:email"{
  397. let alertTitle = NSLocalizedString("Email Already Registered", comment: "")
  398. let alertMessage = NSLocalizedString("Exit and try recovering your account", comment: "")
  399. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  400. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  401. taskViewController.present(alert, animated: true, completion: nil)
  402. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  403. }
  404. else if response_reg == "Error:token"{
  405. let alertTitle = NSLocalizedString("Phone Already Used", comment: "")
  406. let alertMessage = NSLocalizedString("This phone has been used to create an account already. Please contact your mentor.", comment: "")
  407. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  408. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  409. taskViewController.present(alert, animated: true, completion: nil)
  410. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  411. }
  412. else{
  413. UserDefaults.standard.set(true, forKey: "registered")
  414. UserDefaults.standard.synchronize()
  415. // let vc = ResearchContainerViewController()
  416. // self.present(vc, animated: true, completion: nil)
  417. performSegue(withIdentifier: "unwindToStudy", sender: nil)
  418. // performSegue(withIdentifier: "toStudy2", sender: self)
  419. }
  420. // else{
  421. // present(taskViewController, animated: true){
  422. // let completionStep = ORKCompletionStep(identifier: "CompletionStep")
  423. // completionStep.title = "Welcome aboard."
  424. // completionStep.text = "Thank you for joining this study."
  425. // let orderedTask = ORKOrderedTask(identifier: "Join", steps: [completionStep])
  426. // let c_taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  427. // c_taskViewController.delegate = self
  428. // taskViewController.present(c_taskViewController, animated: true)
  429. // }
  430. // }
  431. }
  432. case .discarded, .failed, .saved:
  433. dismiss(animated: true, completion: nil)
  434. }
  435. }
  436. }
  437. //extension NSLayoutConstraint {
  438. //
  439. // override public var description: String {
  440. // let id = identifier ?? ""
  441. // return "id: \(id), constant: \(constant)" //you may print whatever you want here
  442. // }
  443. //}