let manager: Alamofire.Manager = {            let manager = Alamofire.Manager.sharedInstance            manager.delegate.sessionDidReceiveChallenge = { session, challenge in                var disposition: NSURLSessionAuthChallengeDisposition = .PerformDefaultHandling                var credential: NSURLCredential?                                if challenge.PRotectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {                    disposition = NSURLSessionAuthChallengeDisposition.UseCredential                    credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)                } else {                    if challenge.previousFailureCount > 0 {                        disposition = .CancelAuthenticationChallenge                    } else {                        credential = manager.session.configuration.URLCredentialStorage?.defaultCredentialForProtectionSpace(challenge.protectionSpace)                                                if credential != nil {                            disposition = .UseCredential                        }                    }                }                return (disposition, credential)            }            return manager        }()二、 UIWebView 配置https(因為我的工程全是swift寫的,貼上swift代碼,oc自己轉吧!)
主要實現NSURLConnectionDelegate兩個代理方法:func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool {        return (protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust)    }    func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) {        if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {            challenge.sender!.useCredential(NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!), forAuthenticationChallenge: challenge)            challenge.sender!.continueWithoutCredentialForAuthenticationChallenge(challenge)        }            }這樣就搞定了 ,坑了我兩天啊,swift的更是不好找!本人菜鳥,哪不對歡迎提出
新聞熱點
疑難解答