出现这个错误的的原因一般是,https所致,
方法一:可以通过更改工程plist文件,对要下载文件的URL的host做设置,如下:
方法二:在相应的vc,我是vc里边调用下载方法抱着个错误,可以实现如下代理方法:
遵守代理,设置代理:
@interface DownLoadFileManager : NSObject<NSURLSessionDataDelegate>
-(NSURLSession *)session{ if (!_session) { _session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[[NSOperationQueue alloc] init] ]; } return _session; }
实现方法:
-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{ completionHandler(NSURLSessionAuthChallengeUseCredential,[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]); }
更多问题,欢迎加群一起讨论:565191947