I am getting this
"load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled""
when trying to call the api in my custom framework. but when I run the same code in another project, it works fine and give the proper response. below is my code. Is there anything I have to do in custom framework which does not require in normal project.
func invokePostWebServiceCallLogin(request : String,param : NSDictionary,completion : @escaping (_ webResponse : WebserviceResponseClass) ->Void) -> Void {
let headers = [
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
]
let passingParameter : [ String : AnyObject] = param as! [String : AnyObject]
UIApplication.shared.isNetworkActivityIndicatorVisible = true
WebServiceHelperClass.Manager.request(URL(string: request)!, method: .post, parameters: passingParameter,encoding: URLEncoding.default, headers: headers).validate().responseJSON {
response in
UIApplication.shared.isNetworkActivityIndicatorVisible = false
switch response.result {
case .success:
let webResult = WebserviceResponseClass()
webResult.isSuccess = true
webResult.responseData = response.data as NSData?
webResult.error = nil
completion(webResult)
break
case .failure(let error):
let webResult = WebserviceResponseClass()
webResult.isSuccess = false
webResult.responseData = nil
webResult.error = error as NSError
completion(webResult)
}
}
}
private static var Manager : Alamofire.SessionManager = {
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"dev.xxxxx.com": .pinCertificates(
certificates: ServerTrustPolicy.certificates(),
validateCertificateChain: true,
validateHost: true
),
"xx.xx.xxx.xx": .disableEvaluation
]
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 45
configuration.timeoutIntervalForResource = 45
let manager = Alamofire.SessionManager(
configuration: configuration,
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
return manager
}
Task <91C7555E-F6E6-45EB-9762-EE61915719DE>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey= https://dev.xxxxxxxx.com:xxxx/api/VirtualAPI/Login , NSErrorFailingURLKey= https://dev.xxxxxxxx.com:xxxx/api/VirtualAPI/Login , _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <91C7555E-F6E6-45EB-9762-EE61915719DE>.<1>" ), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <91C7555E-F6E6-45EB-9762-EE61915719DE>.<1>, NSLocalizedDescription=cancelled} [-999]
Looks like the API call is using certificate pinning security policy. When the certificate pinning fails the data task will return with NSLocalizedDescription=cancelled
. Check the ServerTrustPolicy.certificates()
and see that it's returning a valid certificate data - usually it automatically load any certificates that are in the SAME bundle. If not make sure to load it manually
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.