Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async(execute: {
- let taskID = self.beginBackgroundUpdateTask()
- print("background taks started:")
- print(taskID)
- if let userusername: String = Keychain(service: KCservice, accessGroup: KCaccessGroup).accessibility(.afterFirstUnlock)["userusername"] {
- if userusername != ""{
- if let userpassword: String = Keychain(service: KCservice, accessGroup: KCaccessGroup).accessibility(.afterFirstUnlock)["userpassword"] {
- if userpassword != ""{
- let loginString = String(format: "%@:%@", userusername, userpassword)
- let loginData = loginString.data(using: String.Encoding.utf8)!
- let base64LoginString = loginData.base64EncodedString()
- let url = URL(string: "\(polyserver)oauth/v2/user/tokens")
- let postParams: [String : Any] = [:]
- var request = URLRequest(url: url!)
- request.httpMethod = "DELETE"
- request.setValue("application/json", forHTTPHeaderField: "Content-Type")
- request.setValue("basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
- request.setValue("no-cache", forHTTPHeaderField: "Cache-Control")
- do
- {
- request.httpBody = try JSONSerialization.data(withJSONObject: postParams, options: JSONSerialization.WritingOptions())
- }
- catch
- {
- print("Caught an error: \(error)")
- }
- let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
- guard error == nil && data != nil else { // check for fundamental networking error
- print("error=\(String(describing: error))")
- self.endBackgroundUpdateTask(taskID)
- return
- }
- if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
- print("statusCode should be 200, but is \(httpStatus.statusCode)")
- print("response = \(String(describing: response))")
- self.endBackgroundUpdateTask(taskID)
- return
- }
- let responseString = String(data: data!, encoding: String.Encoding.utf8)
- print("responseString = \(String(describing: responseString))")
- self.endBackgroundUpdateTask(taskID)
- }
- task.resume()
- }else{self.endBackgroundUpdateTask(taskID)}
- }else{self.endBackgroundUpdateTask(taskID)}
- }else{self.endBackgroundUpdateTask(taskID)}
- }else{self.endBackgroundUpdateTask(taskID)}
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement