我在邮递员中遇到了一个API,我得到的响应很好。但是,当我在我的iOS应用程序中点击相同的API时,它显示的响应为零,结果是错误。我已经打印了错误,它向我显示了此信息,Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline.
我检查了我的互联网连接是否正常。如果可以,我已经搜索了其他站点的互联网连接。但是,它始终向我显示此错误。我感到困惑,为什么它向我显示此错误。我打api的代码是
class WalletDetailService{
static let instance = WalletDetailService()
var getWalletDetailModelArray = [WalletDetail]()
var status:Int = 0
func getWalletDetails(param:[String : String],completion:@escaping CompletionHandler){
let header = [
"auth": "2dd7cfb3c40b4830b72be2cc90276fd9"
]
print(header)
let url = URL(string: getWalletDetailsUrl)
Alamofire.request(url!, method: .post, parameters: param, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in
print("Request: \(String(describing: response.request))") // original url request
print("Response: \(String(describing: response.response))") // http url response
print("Result: \(response.result)")// response serialization result
if response.result.error == nil{
guard let data = response.data else {return}
do{
if let json = try JSON(data: data).dictionary{
let result = json["result"]?.dictionary
let monthlyRental = result!["monthly_rental"]?.intValue
print(monthlyRental!)
}
completion(true)
}
completion(true)
}catch let jsonErr{
print(jsonErr)
}
}else{
completion(false)
debugPrint(response.result.error as Any)
}
}
}
}