Checking Http Status Swift4

萝らか妹 提交于 2019-12-04 20:49:51

Try this code

func checkStatusCode(response:URLResponse?) -> Bool {
        guard let statusCode = (response as? HTTPURLResponse)?.statusCode else {
            print("Invalid Response")
            return false
        }

        if statusCode != 200 {
            print("Invalid File")            
            return false
        }
        return true
    }

Usage:

if (self.checkStatusCode(response: response)) { 
    DispatchQueue.main.async {
        self.performSegue(withIdentifier: "showW", sender: self)
    }      
} else {
 //added an alert 
}  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!