The result of the work should be SMS to the user, which for some reason comes 2 times, Java code with Android app sends 1 SMS, so problems with the server are excluded

let url2=URL(string:"здесь урл="+PhoneTextField.text!) let config = URLSessionConfiguration.default let userPasswordString = "user:pass" let userPasswordData = userPasswordString.data(using: String.Encoding.utf8) let base64EncodedCredential = userPasswordData! let authString = "Basic \(base64EncodedCredential)" config.httpAdditionalHeaders = ["Authorization" : authString] config.requestCachePolicy = .reloadIgnoringLocalCacheData config.urlCache = nil URLCache.shared.removeAllCachedResponses() let session = URLSession.init(configuration: config) let task=session.dataTask(with: url2!){ ( data, response, error) in let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue) self.dataStringJSon=dataString as String? if(self.dataStringJSon!=="User not found"){ }else{ DispatchQueue.main.async { let storyboard = UIStoryboard(name: "Main", bundle: nil); let vc = storyboard.instantiateViewController(withIdentifier: "MySecondSecreen") as! UIViewController; self.present(vc, animated: true, completion: nil); } } } task.resume() 
  • Run a web proxy, see if something is sent exactly two times. There are no problems in the code. perhaps this whole block of code is executed twice - put a breakpoint on task.resume - Max Mikheyenko
  • After disabling the basic auth on the server, requests are no longer duplicated - Maxim

0