1.將cer證書拖到項(xiàng)目工程中
2.獲取cerPath文件路徑,讀取cerData
3.使用 AFSSLPinningModeCertificate創(chuàng)建AFSecurityPolicy對(duì)象
4.參數(shù) securityPolicy.allowInvalidCertificates 設(shè)置允許無(wú)效證書
5.參數(shù) securityPolicy.validatesDomainName 驗(yàn)證域名
6.設(shè)置證書
7.將security對(duì)象賦值給manager 開始網(wǎng)絡(luò)請(qǐng)求
NSString * cerPath = [[NSBundle mainBundle]pathForResource:@"poc_server" ofType:@"cer"];
NSData * cerData = [NSData dataWithContentsOfFile:cerPath];
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
securityPolicy.allowInvalidCertificates = YES;
securityPolicy.validatesDomainName = YES;
securityPolicy.pinnedCertificates = [NSSet setWithObject:cerData];
manager.securityPolicy = securityPolicy;