func connection(urlRequest:NSURLRequest,rest:RESTFull?,completion: (AnyObject?,NSError?)->VoID){ let req = request(urlRequest).responseJsON(options: .AllowFragments) { (_,response,data,error) -> VoID in if let actualData: AnyObject = data { completion(actualData,nil) }else { completion(nil,error) } } req.delegate.taskDIDReceiveChallenge = { session,_,challenge in println("Got challenge: \(challenge),in session \(session)") var disposition: NSURLSessionAuthChallengedisposition = .UseCredential var credential: NSURLCredential = NSURLCredential() if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust){ disposition = NSURLSessionAuthChallengedisposition.UseCredential credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!) } return(disposition,credential) }}解决方法 您无法将值设置为Request Class的taskDIDReceiveChallenge.您可以改用Manager类的委托.
Manager.sharedInstance.delegate.taskDIDReceiveChallenge = { session,challenge in print("Got challenge: \(challenge),in session \(session)") var disposition: NSURLSessionAuthChallengedisposition = .UseCredential var credential: NSURLCredential = NSURLCredential() if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust){ disposition = NSURLSessionAuthChallengedisposition.UseCredential credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!) } return(disposition,credential)}总结
以上是内存溢出为你收集整理的swift – Alamofire不处理身份验证挑战全部内容,希望文章能够帮你解决swift – Alamofire不处理身份验证挑战所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)