出于某种原因,自从添加AwaitKit以来,Alamofire不是delivering
的响应。
这是我的代码:
return Promise { resolve, reject in
Alamofire.request(url, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseString { response in
if (response.error != nil) {
reject(response.error!)
} else {
switch response.result {
case .success:
var result: Any? = response.result.value
if let body = result as? String {
let data = body.data(using: .utf8)!
if body.starts(with: "{") || body.starts(with: "[") {
do {
result = try JSONSerialization.jsonObject(with: data, options : .allowFragments)
} catch let error as NSError {
print(error)
}
}
}
if response.response!.statusCode == 200 {
resolve(result)
} else {
reject(APIError(status: response.response!.statusCode, code: result))
}
break
case .failure(let error):
reject(error)
break
}
}
}
}
我可以看到网址已被点击,请求也已完成,但应用中没有任何操作。