iOS 过滤下载资源类型

以视频下载为例:

在做下载功能时,有时候会遇到后台给提供了非视频资源的下载链接,
如下方法可将非视频资源过滤掉

#pragma mark - NSURLSessionDelegate
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSHTTPURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler {
   
    NSString *miniType = response.MIMEType; //有时后台错误,给的下载链接为非视频
    if(download && download.DownloadState == PVR_DOWNLOAD_RUN){
        if ([NSString isEmpty:miniType] || ![miniType hasPrefix:@"video"]) {
            NSLog(@"资源地址为空,或不是视频类资源");
}

你可能感兴趣的:(iOS 过滤下载资源类型)