Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.20 KB | None | 0 0
  1.  
  2. class AuxiliaryRequests {
  3.    
  4.    
  5.     static func getSocketData(currentViewController: UIViewController, closure: @escaping () -> ()) {
  6.        
  7.         let timestampSeconds = Int(NSDate().timeIntervalSince1970)
  8.        
  9.         _ = APIManager.sharedInstance.getSocketData(timestamp: timestampSeconds){ error, json in
  10.            
  11.            
  12.             if let e = error {
  13.                 print(e)
  14.                
  15.                 if json != nil {
  16.                    
  17.                     print(json!)
  18.                    
  19.                     if let message = json!["message"].string {
  20.                        
  21.                         print("GET SOCKET DATA MESSAGE: \(message)")
  22.                         if message == "invalid_token" || message == "not_authorized_device" {
  23.                            
  24.                             AuxiliaryFunctions.logOut(currentViewController: currentViewController)
  25.                            
  26.                         }
  27.                     }
  28.                 }
  29.                
  30.             } else {
  31.                
  32.                 //print(json!)
  33.                 print("SOCKET DATA GET")
  34.                
  35.                 UserDefaults.standard.setSocketSocId(value: json!["data"]["socid"].stringValue)
  36.                 UserDefaults.standard.setSocketUId(value: json!["data"]["uid"].stringValue)
  37.                 UserDefaults.standard.setSocketVerify(value: json!["data"]["verify"].stringValue)
  38.                
  39.                 getSocketHost(currentViewController: currentViewController, closure: closure)
  40.                
  41.             }
  42.         }
  43.     }
  44.    
  45.    
  46.     static func getSocketHost(currentViewController: UIViewController, closure: @escaping () -> ()) {
  47.        
  48.        
  49.         let parameters: Parameters = [
  50.            
  51.             "socid": UserDefaults.standard.getSocketSocId(),
  52.             "uid": UserDefaults.standard.getSocketUId(),
  53.             "verify": UserDefaults.standard.getSocketVerify()
  54.            
  55.         ]
  56.        
  57.        
  58.         let timestampSeconds = Int(NSDate().timeIntervalSince1970)
  59.        
  60.         _ = APIManager.sharedInstance.getSocketHost(timestamp: timestampSeconds, parameters: parameters){ error, json in
  61.            
  62.            
  63.             if let e = error {
  64.                 print(e)
  65.                
  66.                 if json != nil {
  67.                    
  68.                     print(json!)
  69.                    
  70.                     if let message = json!["message"].string {
  71.                        
  72.                         print("GET SOCKET HOST MESSAGE: \(message)")
  73.                         if message == "invalid_token" || message == "not_authorized_device" {
  74.                            
  75.                             AuxiliaryFunctions.logOut(currentViewController: currentViewController)
  76.                            
  77.                         }
  78.                     }
  79.                 }
  80.                
  81.             } else {
  82.                
  83.                 //print(json!)
  84.                 print("SOCKET HOST GET")
  85.                
  86.                 UserDefaults.standard.setSocketHost(value: json!["data"]["host"].stringValue)
  87.                 closure()
  88.                
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement