如果服務器是持有自簽名證書,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]);
}