0
class ViewController: UIViewController {

    @IBOutlet weak var userNameTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!

    var errorCode:Int?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }





    @IBAction func buttonSubimit(_ sender: Any) {

         offlineAPiHit()


    }


    func offlineAPiHit(){

        let url:String = "myAPi?MasterID=\(userNameTextField.text!)&Password=\(passwordTextField.text!)&IMEI=0&Version=0&SecurityCode=0000&DeviceID=0&DeviceType=A"
         print("MyURL",url)

        Alamofire.request(url, method: .get, parameters:nil, encoding: URLEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in
            switch(response.result) {
            case .success(_):

                if let data = response.result.value{

                    print("sucess",response.result.value)
                }
                break

            case .failure(_):
                let error  = response.result.error!.localizedDescription
               // self.displayAlertMessage(messageToDisplay: error)
                print("faliure",response.result.error!)


               // self.displayAlertMessage(messageToDisplay: "Something Wrong Please try again")
                break
         //store Data 
// After offline to online Api hit


            }

in Error function i store userName And user password. but when reconnecting internet second time i can't hit api .So how to i sync all the data that time

Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40
  • 1
    https://stackoverflow.com/questions/30743408/check-for-internet-connection-with-swift here you can find some code to observe when your internet connection will be back online, then you can just call the function again – Vollan Jul 15 '19 at 09:56
  • I can't understand. Can you please explain this ? –  Jul 15 '19 at 11:01
  • https://stackoverflow.com/a/49571819/4757272 Here is an easier explanation. – Vollan Jul 15 '19 at 11:18

0 Answers0