123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // ResearchContainerViewController.swift
- // EncuestaMarle
- //
- // Created by Tatiana Castro on 5/20/19.
- // Copyright © 2019 Marle. All rights reserved.
- //
-
- import UIKit
- import ResearchKit
-
- var response_token = false
-
- //func checkToken(){
- //
- // let request = NSMutableURLRequest(url: NSURL(string: "http://emaapp.online/checkToken.php")! as URL)
- // request.httpMethod = "POST"
- // let postString = "data=\(token)"
- // request.httpBody = postString.data(using: String.Encoding.utf8)
- //
- // let task = URLSession.shared.dataTask(with: request as URLRequest) {
- // data, response, error in
- //
- // if error != nil {
- // print("error=\(String(describing: error))")
- // return
- // }
- //
- // print("response = \(String(describing: response))")
- //
- // let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
- // print("responseString = \(String(describing: responseString))")
- // if((responseString) == "true")
- // {
- // response_token=true
- // }
- // }
- // task.resume()
- //}
-
- func checkToken()
- {
- //
- // Getting
-
- if let user_token = UserDefaults.standard.string(forKey: "user_token") {
- //print(stringOne) // Some String Value
- token=user_token
- response_token=true
- }
-
- }
-
- func checkIfRegister() -> Bool
- {
- //
- // Getting
- var registered = false
- if(UserDefaults.standard.bool(forKey: "registered"))
- {
- registered = UserDefaults.standard.bool(forKey: "registered")
- }
-
- return registered
-
- }
-
-
- class ResearchContainerViewController: UIViewController {
-
- var contentHidden = false {
- didSet {
- guard contentHidden != oldValue && isViewLoaded else { return }
- children.first?.view.isHidden = contentHidden
- }
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- let registered = checkIfRegister()
- //if response_token == true {
- if registered == true {
- print("$$$$$$$Esta registrada$$$$$$$$$")
- performSegue(withIdentifier: "toStudy", sender: nil) }
- else {
- performSegue(withIdentifier: "toOnboarding", sender: self)
- }
- }
-
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- super.prepare(for: segue, sender: sender)
- }
-
- @IBAction func unwindToStudy(_ segue: UIStoryboardSegue) {
- performSegue(withIdentifier: "toStudy", sender: self)
-
- }
- @IBAction func unwindToWithdrawl(_ segue: UIStoryboardSegue) {
- toWithdrawl()
- }
- func toWithdrawl() {
- let viewController = WithdrawViewController()
- viewController.delegate = self as? ORKTaskViewControllerDelegate
-
- present(viewController, animated: true, completion: nil)
- }
-
- }
-
- extension ResearchContainerViewController: ORKTaskViewControllerDelegate {
-
- public func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
- // Check if the user has finished the `WithdrawViewController`.
- if taskViewController is WithdrawViewController {
- if reason == .completed {
- performSegue(withIdentifier: "toOnboarding", sender: self)
- }
- dismiss(animated: true, completion: nil)
- }
- }
- }
-
|