let APIURL="http://www.mrdubo.com/api/api.php"
let url=URL(string: APIURL)
//创建请求对象
let urlRequest:NSURLRequest = NSURLRequest(url: url!)
let ur:NSURLRequest=NSURLRequest(url: url!, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalCacheData , timeoutInterval: 5)
//响应对象
var response:URLResponse?
do{
//发送请求
let jsonData:NSData? = try NSURLConnection.sendSynchronousRequest(urlRequest as URLRequest,returning: &response) as NSData?
if jsonData==nil {
print("error")
exit(-1)
}
}catch let error as NSError{
//打印错误消息
var alterView = UIAlertController()
alterView.title="Network"
alterView.message="Network not allowed"
var cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel, handler: nil)
alterView.addAction(cancelAction)
self.present(alterView,animated: true, completion: nil)
}
}