No Description

OnboardingViewController.swift 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // OnboardingViewController.swift
  3. // EncuestaMarle
  4. //
  5. // Created by Tatiana Castro on 5/21/19.
  6. // Copyright © 2019 TANIA. 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[4]["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. // Apple removed .includeJob so I removed from the middle possition here
  198. let registrationOptions: ORKRegistrationStepOption = [.includeGender, .includeDOB]
  199. let registrationStep = ORKRegistrationStep(identifier: "registration", title: registrationTitle, text: "Register for TANIA Study", passcodeValidationRegularExpression: passcodeValidationRegularExpression, passcodeInvalidMessage: passcodeInvalidMessage, options: registrationOptions)
  200. let signature = consentDocument.signatures!.first!
  201. let reviewConsentStep = ORKConsentReviewStep(identifier: "ConsentReviewStep", signature: signature, in: consentDocument)
  202. reviewConsentStep.text = "Review the consent form."
  203. reviewConsentStep.reasonForConsent = "Consent to join the TANIA Study."
  204. let passcodeStep = ORKPasscodeStep(identifier: "Passcode")
  205. passcodeStep.text = "Now you will create a passcode to identify yourself to the app and protect access to information you've entered."
  206. let completionStep = ORKCompletionStep(identifier: "CompletionStep")
  207. completionStep.title = "Welcome aboard."
  208. completionStep.text = "Thank you for joining this study."
  209. print("checko")
  210. task_def = "registration"
  211. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep])
  212. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  213. taskViewController.delegate = self
  214. if response_reg == "Error:Email"{
  215. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep])
  216. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  217. taskViewController.delegate = self
  218. present(taskViewController, animated: true){
  219. let alertTitle = NSLocalizedString("Error: Email Already Registered", comment: "")
  220. let alertMessage = NSLocalizedString("Exit and try recovering your account", comment: "")
  221. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  222. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  223. taskViewController.present(alert, animated: true, completion: nil)
  224. self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  225. }
  226. }
  227. else if response_reg == "Error:Token"{
  228. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep])
  229. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  230. taskViewController.delegate = self
  231. present(taskViewController, animated: true){
  232. let alertTitle = NSLocalizedString("Error: Phone Already Used", comment: "")
  233. let alertMessage = NSLocalizedString("This phone has been used to create an account already. Please contact your mentor.", comment: "")
  234. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  235. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  236. taskViewController.present(alert, animated: true, completion: nil)
  237. self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  238. }
  239. }
  240. else{
  241. let c_orderedTask = ORKOrderedTask(identifier: "Join", steps: [consentStep, reviewConsentStep, registrationStep, completionStep])
  242. let c_taskViewController = ORKTaskViewController(task: c_orderedTask, taskRun: nil)
  243. c_taskViewController.delegate = self
  244. present(c_taskViewController, animated: true, completion: nil)
  245. let taskViewController = ORKTaskViewController(task: EncuestaMarle, taskRun: nil)
  246. taskViewController.delegate = (self as ORKTaskViewControllerDelegate)
  247. present(taskViewController, animated: true, completion: nil)
  248. }
  249. }
  250. @IBAction func recover_account(_ sender: UIButton) {
  251. class LoginViewController : ORKLoginStepViewController {
  252. override func forgotPasswordButtonTapped() {
  253. var email: String = ""
  254. let alertTitle = NSLocalizedString("Enter your email", comment: "")
  255. let alertMessage = NSLocalizedString("You will recieve instructions to reset your password.", comment: "")
  256. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  257. alert.addTextField { (textField) in
  258. textField.placeholder = "Email"
  259. }
  260. alert.addAction(UIAlertAction(title: "Submit", style: UIAlertAction.Style.default, handler: { [weak alert] (_) in
  261. let textField = alert!.textFields![0] // Force unwrapping because we know it exists.
  262. print("Text field email: \(String(describing: textField.text))")
  263. email = textField.text!
  264. sendEmail(email: email)
  265. let alertTitle2 = NSLocalizedString("If the email is registered we will send you an email", comment: "")
  266. let alertMessage2 = NSLocalizedString("Check \(email) for instructions to reset your password", comment: "")
  267. let alert2 = UIAlertController(title: alertTitle2, message: alertMessage2, preferredStyle: UIAlertController.Style.alert)
  268. alert2.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  269. self.present(alert2, animated: true, completion: nil)
  270. }))
  271. alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel , handler: nil))
  272. self.present(alert, animated: true, completion: nil)
  273. }
  274. }
  275. let loginTitle = NSLocalizedString("Recover Account", comment: "")
  276. let loginStep = ORKLoginStep(identifier: "recover" , title: loginTitle, text: "Fill out information to recover account", loginViewControllerClass: LoginViewController.self)
  277. let orderedTask = ORKOrderedTask(identifier: "Join", steps: [loginStep])
  278. let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  279. taskViewController.delegate = self
  280. if (resetPassword) {
  281. task_def = "reset"
  282. resetPassword = false
  283. let alertTitle2 = NSLocalizedString("Email will arrive soon", comment: "")
  284. let alertMessage2 = NSLocalizedString("Check your inbox for instructions to reset your password", comment: "")
  285. let alert2 = UIAlertController(title: alertTitle2, message: alertMessage2, preferredStyle: UIAlertController.Style.alert)
  286. alert2.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  287. self.present(alert2, animated: true, completion: nil)
  288. }
  289. else {
  290. task_def = "recover"
  291. }
  292. present(taskViewController, animated: true, completion: nil)
  293. }
  294. }
  295. extension OnboardingViewController : ORKTaskViewControllerDelegate {
  296. public func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
  297. switch reason {
  298. case .completed:
  299. if task_def == "reset" {
  300. let taskResult_reset = taskViewController.result
  301. let jsonData_reset = try! ORKESerializer.jsonData(for: taskResult_reset)
  302. jsonString_reset = NSString(data: jsonData_reset, encoding: String.Encoding.utf8.rawValue)! as String
  303. jsonDict_reset = convertToDictionary(text: jsonString_r as String) as! [String: Any]
  304. do {
  305. let jsonData_reset = try JSONSerialization.data(withJSONObject: jsonDict_reset, options: .prettyPrinted)
  306. jsonString_reset = NSString(data: jsonData_reset, encoding: String.Encoding.utf8.rawValue)! as String
  307. }
  308. catch {
  309. print(error.localizedDescription)
  310. }
  311. //sendEmail()
  312. }
  313. else if task_def == "recover"{
  314. let taskResult_r = taskViewController.result
  315. let jsonData_r = try! ORKESerializer.jsonData(for: taskResult_r)
  316. jsonString_r = NSString(data: jsonData_r, encoding: String.Encoding.utf8.rawValue)! as String
  317. jsonDict_r = convertToDictionary(text: jsonString_r as String) as! [String: Any]
  318. do {
  319. let jsonData_r = try JSONSerialization.data(withJSONObject: jsonDict_r, options: .prettyPrinted)
  320. jsonString_r = NSString(data: jsonData_r, encoding: String.Encoding.utf8.rawValue)! as String
  321. }
  322. catch {
  323. print(error.localizedDescription)
  324. }
  325. sendJson_r()
  326. // TODO:
  327. // THIS REPRESENTS HOW TO RESPOND TO WRONG INPUT
  328. while(newResponseR == false) {}
  329. newResponseR = false
  330. // implement if (resetPassword == true) workflow
  331. if (response_r == "Error:hash" || response_r == "Error:password" || response_r == "Error:Email") {
  332. let alertTitle = NSLocalizedString("Email and Password do not match", comment: "")
  333. let alertMessage = NSLocalizedString("Try again or tap forgot password.", comment: "")
  334. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  335. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  336. taskViewController.present(alert, animated: true, completion: nil)
  337. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  338. }
  339. else if response_r == "Error:token"{
  340. let alertTitle = NSLocalizedString("Phone already registered", comment: "")
  341. 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: "")
  342. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  343. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  344. taskViewController.present(alert, animated: true, completion: nil)
  345. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  346. }
  347. else {
  348. UserDefaults.standard.set(true, forKey: "registered")
  349. UserDefaults.standard.synchronize()
  350. // MARK: Restore PDF here
  351. // let decodedString = Data(base64Encoded: response_r)
  352. // var docURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last as NSURL?
  353. // docURL = docURL?.appendingPathComponent("ConsentDocument.pdf") as NSURL?
  354. //
  355. // do {
  356. // try decodedString?.write(to:docURL! as URL)
  357. // print("PDF written to disk from recovery ✅")
  358. // print(docURL! as URL)
  359. //
  360. // } catch let error {
  361. // print("❌")
  362. // print(error.localizedDescription)
  363. //
  364. // }
  365. performSegue(withIdentifier: "unwindToStudy", sender: nil)
  366. }
  367. }
  368. else{
  369. let taskResult_reg = taskViewController.result
  370. if let stepResult = taskResult_reg.stepResult(forStepIdentifier: "ConsentReviewStep"),
  371. let signatureResult = stepResult.results?.first as? ORKConsentSignatureResult {
  372. print("Signature generated ✅")
  373. print(signatureResult)
  374. let signatureDate = signatureResult.endDate
  375. // lets try to make a pdf for this
  376. let documentCopy = consentDocument
  377. signatureResult.apply(to: documentCopy)
  378. documentCopy.makePDF { (data, error) -> Void in
  379. var docURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last as NSURL?
  380. docURL = docURL?.appendingPathComponent("ConsentDocument.pdf") as NSURL?
  381. do {
  382. try data?.write(to:docURL! as URL)
  383. print("PDF written to disk ✅")
  384. print(docURL! as URL)
  385. if let pdfBase64 = data?.base64EncodedString() {
  386. sendPDF(pdfBase64, signatureDate)
  387. }
  388. } catch let error {
  389. print("❌")
  390. print(error.localizedDescription)
  391. }
  392. }
  393. // let sigJson = try! ORKESerializer.jsonData(for: signatureResult)
  394. // print(sigJson.base64EncodedString())
  395. }
  396. let jsonData_reg = try! ORKESerializer.jsonData(for: taskResult_reg)
  397. jsonString_reg = NSString(data: jsonData_reg, encoding: String.Encoding.utf8.rawValue)! as String
  398. jsonDict_reg = convertToDictionary(text: jsonString_reg as String) as! [String: Any]
  399. limpiarJson_reg()
  400. do {
  401. let jsonData_reg = try JSONSerialization.data(withJSONObject: n_jsonDict_reg, options: .prettyPrinted)
  402. jsonString_reg = NSString(data: jsonData_reg, encoding: String.Encoding.utf8.rawValue)! as String
  403. }
  404. catch {
  405. print(error.localizedDescription)
  406. }
  407. // TODO:
  408. // MAYBE THIS DOES IT BETTER
  409. sendJson_reg()
  410. while(newResponseReg == false) {}
  411. newResponseReg = false
  412. if response_reg == "Error:email"{
  413. let alertTitle = NSLocalizedString("Email Already Registered", comment: "")
  414. let alertMessage = NSLocalizedString("Exit and try recovering your account", comment: "")
  415. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  416. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  417. taskViewController.present(alert, animated: true, completion: nil)
  418. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  419. }
  420. else if response_reg == "Error:token"{
  421. let alertTitle = NSLocalizedString("Phone Already Used", comment: "")
  422. let alertMessage = NSLocalizedString("This phone has been used to create an account already. Please contact your mentor.", comment: "")
  423. let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
  424. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  425. taskViewController.present(alert, animated: true, completion: nil)
  426. //self.performSegue(withIdentifier: "toOnboarding", sender: nil)
  427. }
  428. else{
  429. UserDefaults.standard.set(true, forKey: "registered")
  430. UserDefaults.standard.synchronize()
  431. // let vc = ResearchContainerViewController()
  432. // self.present(vc, animated: true, completion: nil)
  433. performSegue(withIdentifier: "unwindToStudy", sender: nil)
  434. // performSegue(withIdentifier: "toStudy2", sender: self)
  435. }
  436. // else{
  437. // present(taskViewController, animated: true){
  438. // let completionStep = ORKCompletionStep(identifier: "CompletionStep")
  439. // completionStep.title = "Welcome aboard."
  440. // completionStep.text = "Thank you for joining this study."
  441. // let orderedTask = ORKOrderedTask(identifier: "Join", steps: [completionStep])
  442. // let c_taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
  443. // c_taskViewController.delegate = self
  444. // taskViewController.present(c_taskViewController, animated: true)
  445. // }
  446. // }
  447. }
  448. case .discarded, .failed, .saved:
  449. dismiss(animated: true, completion: nil)
  450. }
  451. }
  452. }
  453. @IBDesignable extension UIButton {
  454. @IBInspectable var borderWidth: CGFloat {
  455. set {
  456. layer.borderWidth = newValue
  457. }
  458. get {
  459. return layer.borderWidth
  460. }
  461. }
  462. @IBInspectable var cornerRadius: CGFloat {
  463. set {
  464. layer.cornerRadius = newValue
  465. }
  466. get {
  467. return layer.cornerRadius
  468. }
  469. }
  470. @IBInspectable var borderColor: UIColor? {
  471. set {
  472. guard let uiColor = newValue else { return }
  473. layer.borderColor = uiColor.cgColor
  474. }
  475. get {
  476. guard let color = layer.borderColor else { return nil }
  477. return UIColor(cgColor: color)
  478. }
  479. }
  480. }
  481. //extension NSLayoutConstraint {
  482. //
  483. // override public var description: String {
  484. // let id = identifier ?? ""
  485. // return "id: \(id), constant: \(constant)" //you may print whatever you want here
  486. // }
  487. //}
  488. extension ORKTaskViewController {
  489. override open func viewDidLoad() {
  490. super.viewDidLoad()
  491. if #available(iOS 13, *) {
  492. overrideUserInterfaceStyle = .light
  493. }
  494. }
  495. }