Swift学习

swift Https单向绑定

2017-09-04  本文已影响14人  cocoawork丶

网上找了那么多,基本都是来源于同一出处的,正所谓天下文章一大抄,你抄我来我抄你!

func authentication() {
        let manager = Alamofire.SessionManager.default
        manager.delegate.sessionDidReceiveChallenge = { session, challenge in
            var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling
            var credential: URLCredential?
            if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
                disposition = URLSession.AuthChallengeDisposition.useCredential
                credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
            } else {
                if challenge.previousFailureCount > 0 {
                    disposition = .cancelAuthenticationChallenge
                } else {
                    credential = manager.session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
                    if credential != nil {
                        disposition = .useCredential
                    }
                }
            }
            return (disposition, credential)
        }
    }
let provider = MoyaProvider<JMTAPIManager>(manager: Alamofire.SessionManager.default/*, plugins: [NetworkLoggerPlugin(verbose: true)]*/)
上一篇 下一篇

猜你喜欢

热点阅读