我使用NSURLConnection的貫徹連接:didReceiveAuthenticationChallenge:對委託:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
NSURLProtectionSpace *tmpSpace=[challenge protectionSpace];
SecTrustRef currentServerTrust=[tmpSpace serverTrust];
SecTrustResultType trustResult;
OSStatus err = SecTrustEvaluate(currentServerTrust, &trustResult);
BOOL trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed) || (trustResult == kSecTrustResultUnspecified));
if (trusted){
// Do something
}
}
}
目前,「如果(信任){}」塊僅通過iOS的信任證書的工作,我希望它的工作其他人也是如此,但前提是證書未被撤銷或過期。
的文檔使用SecTrustSettingsSetTrustSettings更改設置並重新評估信任。但我找不到iOS的此方法(或SecTrustSetting),僅適用於Mac。
感謝