Created
October 9, 2019 22:50
-
-
Save carlosalexandresmo/119f9d66651442ea1683a72185421a45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func postDeviceId() { | |
let userDefaults = UserDefaults.standard | |
let deviceToken = userDefaults.string(forKey: Constants.deviceTokenKey)! | |
//print("Device ID: \(deviceToken)") | |
let user = Globals.sharedInstance.loggedUser | |
let name: String = (user?.name)! | |
let url = URL(string: "https://barranoar.peopleon.a2hosted.com/device.php")! | |
var request = URLRequest(url: url) | |
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") | |
request.httpMethod = "POST" | |
let postString = "device_id=\(name)&device_token=\(deviceToken)&device_system=iOS" | |
request.httpBody = postString.data(using: .utf8) | |
let task = URLSession.shared.dataTask(with: request) { data, response, error in | |
guard let data = data, error == nil else { | |
//print("error=\(String(describing: error))") | |
return | |
} | |
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { | |
//print("statusCode should be 200, but is \(httpStatus.statusCode)") | |
//print("response = \(String(describing: response))") | |
} | |
let responseString = String(data: data, encoding: .utf8) | |
//print("responseString = \(String(describing: responseString))") | |
} | |
task.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment