遇到此问题的解决办法:
使用中的didReceiveChallenge方法,方法中的代码如下:
- (void)URLSession:(NSURLSession *)sessiondidReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition,NSURLCredential * __nullable credential))completionHandler
{
NSLog(@"didReceiveChallenge");
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredentialcredentialForTrust:challenge.protectionSpace.serverTrust]);
}
当然,info.plist里面也要加上下面这段:
NSAppTransportSecurity
NSAllowsArbitraryLoads
网友评论