AFNetworking 3.0+ 啟用完整、嚴格的https證書較驗參考程式碼
阿新 • • 發佈:2019-01-30
// 1.初始化單例類 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.securityPolicy.SSLPinningMode = AFSSLPinningModeCertificate; // 2.設定證書模式 NSString * cerPath = [[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"cer"]; NSData * cerData = [NSData dataWithContentsOfFile:cerPath]; manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate withPinnedCertificates:[[NSSet alloc] initWithObjects:cerData, nil]]; manager.securityPolicy.allowInvalidCertificates = NO; [manager.securityPolicy setValidatesDomainName:YES];