[iOS]React-Native fetch访问HTTPS自签名证书服务器错误

如果服务器是持有自签名证书,React-Native fetch访问会报错

解决方法:

找到RCTNetwork.xcodeproj中的RCTHTTPRequestHandler.m文件,
#pragma mark - NSURLSession delegate下面增加以下代码:

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
  completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}

参考StackOverflow

你可能感兴趣的:(移动跨平台)