加载失败,错误代码为错误域= NSURLErrorDomain代码= -999“已取消”

时间:2019-07-25 09:46:07

标签: ios swift alamofire xcode10 dynamic-frameworks

我得到了

  

“加载失败,错误Error Domain = NSURLErrorDomain代码= -999”已取消“”

尝试在我的自定义框架中调用api时。但是当我在另一个项目中运行相同的代码时,它可以正常工作并给出正确的响应。下面是我的代码。在自定义框架中我有什么需要做的,而在普通项目中不需要。

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
    }

  

任务<91C7555E-F6E6-45EB-9762-EE61915719DE>。<1>加载失败,错误为Error Domain = NSURLErrorDomain代码= -999“已取消” UserInfo = {NSErrorFailingURLStringKey = https://dev.xxxxxxxx.com:xxxx/api/VirtualAPI/Login,NSErrorFailingURLKey = {{3 }},_ NSURLErrorRelatedURLSessionTaskErrorKey =(       “ LocalDataTask <91C7555E-F6E6-45EB-9762-EE61915719DE>。<1>”   ),_NSURLErrorFailingURLSessionTaskErrorKey = LocalDataTask <91C7555E-F6E6-45EB-9762-EE61915719DE>。<1>,NSLocalizedDescription = cancelled} [-999]

1 个答案:

答案 0 :(得分:0)

好像API调用正在使用证书固定安全策略。 当证书固定失败时,数据任务将以"test"返回。 检查NSLocalizedDescription=cancelled并查看它是否返回有效的证书数据-通常它会自动加载SAME捆绑软件中的所有证书。 如果没有,请确保手动加载