Handle No Internet Connection Error Before Try to Parse the Result in Alamofire

后端 未结 7 1909
旧巷少年郎
旧巷少年郎 2020-12-30 03:04

How should I handle if there is an error occurs when there is no internet connection in Alamofire. I tried checking if data is nil or not but it does not work.

Below

7条回答
  •  半阙折子戏
    2020-12-30 03:40

    Swift 5.0

    You can check with NSURL-related Error Code

    if error._code == NSURLErrorNotConnectedToInternet {
                            
    }
    

    Or you can check with the code

    if error._code == -1009 {
                            
    }
    

    You can check other code on the developer site. https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes

提交回复
热议问题