There are two ways to support HTTPS in iOS development: one is that the backend has been processed, and the mobile terminal can directly use the HTTPS interface. The other is to give the mobile terminal a server certificate cer file. At this time, we need to import the cer file into our project. The following is the implementation method.
1. Double-click the certificate, and the certificate has been added to the keychain.
2. Drag the cer file into the project
3. If you are using AFNetwotking, add the following code to the code
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; //Certificate AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; = securityPolicy; // 2. Set the certificate mode NSString * cerPath = [[NSBundle mainBundle] pathForResource:@"tomcat" ofType:@"cer"]; //tomcat is the name of the cer file NSData * cerData = [NSData dataWithContentsOfFile:cerPath]; = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate withPinnedCertificates:[[NSSet alloc] initWithObjects:cerData, nil]]; // Whether the client trusts the illegal certificate = YES; // Whether to verify the domain name in the certificate domain field [ setValidatesDomainName:NO];
At this point, the HTTPS support has been completed
The above detailed explanation of the use of cer files for iOS development and implementation of HTTPS is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.
File reference:
/p/6b9c8bd5005a
/kyrios/p/