No Description

WithdrawViewController.swift 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/withdraw.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 = \(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 reset the app to the state it was in prior to you originally joining the study.", 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. withdrawDict["withdraw"]="yes"
  39. do {
  40. let jsonData_w = try JSONSerialization.data(withJSONObject: withdrawDict, options: .prettyPrinted)
  41. jsonString_withdraw = NSString(data: jsonData_w, encoding: String.Encoding.utf8.rawValue)! as String
  42. }
  43. catch {
  44. print(error.localizedDescription)
  45. }
  46. print(jsonString_withdraw)
  47. sendJson_withdraw()
  48. super.init(task: withdrawTask, taskRun: nil)
  49. }
  50. required init(coder aDecoder: NSCoder) {
  51. fatalError("init(coder:) has not been implemented")
  52. }
  53. }