[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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章