ReactNative-https证书无效

iOS解决:


在该文件中,添加过滤证书的代理方法。

-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
  
  NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
  __block NSURLCredential *credential = nil;
  
  if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
    credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
    if (credential) {
      disposition = NSURLSessionAuthChallengeUseCredential;
    } else {
      disposition = NSURLSessionAuthChallengePerformDefaultHandling;
    }
  } else {
    disposition = NSURLSessionAuthChallengePerformDefaultHandling;
  }
  
  if (completionHandler) {
    completionHandler(disposition, credential);
  }
}

猜你喜欢

转载自blog.csdn.net/Crazy_SunShine/article/details/80651687
今日推荐