#If OBJC
…..
NSURLSession = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
[[urlSession dataTaskWithURL:[NSURL URLWithString:urlstring] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error == NULL){
}
else{
}
}] resume];
……
-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
if(myCompareMethod == True ){
NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrustRef];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}
else{
completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, NULL);
}
}