- (AFSecurityPolicy*)customSecurityPolicy { /**** SSL Pinning ****/ NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"你的證書" ofType:@"cer"]; NSData *certData = [NSData dataWithContentsOfFile:cerPath]; AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init]; [securityPolicy setAllowInvalidCertificates:NO]; [securityPolicy setPinnedCertificates:@[certData]]; [securityPolicy setSSLPinningMode:AFSSLPinningModeCertificate]; /**** SSL Pinning ****/ return securityPolicy; }
而後在管理器裏這麼設置css
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; /**** SSL Pinning ****/ [manager setSecurityPolicy:[self customSecurityPolicy]]; /**** SSL Pinning ****/ [manager GET:@"網站的url" parameters:params success:^(AFHTTPRequestOperation *operation, NSDictionary* responseObject) { //這裏是你本身的代碼了 } failure:^(AFHTTPRequestOperation *operation, NSError *error) { //註釋同上 }];