Bez popisu

WithdrawViewController.swift 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // WithdrawViewController.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 withdrawDict = [String: String]()
  11. var jsonString_withdraw = String()
  12. func sendJson_withdraw(){
  13. let request = NSMutableURLRequest(url: NSURL(string: "http://tania.uprrp.edu/withdrawal.php")! as URL)
  14. request.httpMethod = "POST"
  15. let postString = "data=\(jsonString_withdraw)"
  16. request.httpBody = postString.data(using: String.Encoding.utf8)
  17. let task = URLSession.shared.dataTask(with: request as URLRequest) {
  18. data, response, error in
  19. if error != nil {
  20. print("error=\(String(describing: error))")
  21. return
  22. }
  23. let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
  24. print("responseString Withdrawl ❌ = \(String(describing: responseString))")
  25. }
  26. task.resume()
  27. }
  28. class WithdrawViewController: ORKTaskViewController {
  29. init() {
  30. let instructionStep = ORKInstructionStep(identifier: "WithdrawlInstruction")
  31. instructionStep.title = NSLocalizedString("Are you sure you want to withdraw?", comment: "")
  32. instructionStep.text = NSLocalizedString("Withdrawing from the study will delete all your information and reset the app.", comment: "")
  33. let completionStep = ORKCompletionStep(identifier: "Withdraw")
  34. completionStep.title = NSLocalizedString("We appreciate your time.", comment: "")
  35. completionStep.text = NSLocalizedString("Thank you for your contribution to this study. We are sorry that you could not continue.", comment: "")
  36. let withdrawTask = ORKOrderedTask(identifier: "Withdraw", steps: [instructionStep, completionStep])
  37. withdrawDict["token"]=token
  38. do {
  39. let jsonData_w = try JSONSerialization.data(withJSONObject: withdrawDict, options: .prettyPrinted)
  40. jsonString_withdraw = NSString(data: jsonData_w, encoding: String.Encoding.utf8.rawValue)! as String
  41. }
  42. catch {
  43. print(error.localizedDescription)
  44. }
  45. // TODO: Move this to confirmation step
  46. // print("❌ User is withdrawing with string: ")
  47. // print(jsonString_withdraw)
  48. // sendJson_withdraw()
  49. super.init(task: withdrawTask, taskRun: nil)
  50. }
  51. required init(coder aDecoder: NSCoder) {
  52. fatalError("init(coder:) has not been implemented")
  53. }
  54. }