Advertisement
Kwright03

Untitled

Nov 14th, 2018
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.04 KB | None | 0 0
  1.     func checkDeviceRegistry() -> Bool {
  2.         var found: Bool = false
  3.         let url = URL(string: "http://10.51.200.249:3000/api/devices")
  4.        
  5.         let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
  6.            
  7.             if let data = data {
  8.                 do {
  9.                     // Convert the data to JSON
  10.                     let jsonSerialized = try JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]
  11.                    
  12.                     if let json = jsonSerialized, let url = json["url"], let explanation = json["explanation"] {
  13. //                        print(url)
  14. //                        print(explanation)
  15.                         print(json)
  16.                     }
  17.                 }  catch let error as NSError {
  18.                     print(error.localizedDescription)
  19.                 }
  20.             } else if let error = error {
  21.                 print(error.localizedDescription)
  22.             }
  23.         }
  24.        
  25.         task.resume()
  26.         return found
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement