I have integrated Alamofire Library for API calling, and getting following error :
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=57, NSUnderlyingError=0x600000c68990 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask .<1>" ), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=OUR_Server_URL, NSErrorFailingURLKey=OUR_Server_URL, _kCFStreamErrorDomainKey=1}
I have added following property into .plist file too :
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
I am using Alamofire using following code :-
Alamofire code :
func postFormDataWebService(methodType : HTTPMethod, contentType : String, url : String,
parameters : NSMutableDictionary?,
success: @escaping(_ response : NSDictionary, _ status : String) -> Void,
failure: @escaping(_ error : Error, _ status : Int) -> Void){
var headers : HTTPHeaders = [ "Content-Type": contentType, "accept": "application/json"]
Alamofire.request(url, method: methodType, parameters:parameters as? [String : Any] , encoding: JSONEncoding.default, headers: headers)
.responseJSON {
(response:DataResponse) in
var responseStatusCode: Int = 0
switch response.result {
case .success:
responseStatusCode = (response.response?.statusCode)!
let data = response.result.value as! NSDictionary
print(data)
success(data, data["status"] as? String ?? "")
break
case .failure(let error):
responseStatusCode = response.response?.statusCode ?? 0
print("statusCode :: ", response.response?.statusCode ?? 0)
print("Error :: ",error.localizedDescription)
failure(error,responseStatusCode)
}
}
}
API Calling function :
ApiManager.shared.postFormDataWebService(methodType: :POST, contentType: "application/json", url: LoginUrl, parameters: parameters,
success: { (response, status) in
print("response = \(response)")
print("status = \(status)")
}) { (error, status) in
print("Login Error == \(error)\nStatus == \(status)")
}
Any help would be appreciated.