我正在尝试暂停下载任务(如果正在下载)。但是AVAssetDownloadTask状态始终显示为暂停,即使正在进行正在进行的下载。
assetName = [assetName stringByReplacingOccurrencesOfString:@" " withString:@"++"];
NSURLSessionConfiguration *urlSessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:[NSString stringWithFormat:@"%@",assetName]];
urlSessionConfiguration.discretionary = YES;
urlSessionConfiguration.sessionSendsLaunchEvents = YES;
// Create a new AVAssetDownloadURLSession with background configuration, delegate, and queue
AVAssetDownloadURLSession *avAssetDownloadSession = [AVAssetDownloadURLSession sessionWithConfiguration:urlSessionConfiguration assetDownloadDelegate:self delegateQueue:[NSOperationQueue mainQueue]];
AVURLAsset *hlsAsset = [AVURLAsset assetWithURL:url];
if (@available(iOS 10.0, *)) {
//[AVAssetDownloadTaskMediaSelectionKey: mediaSelection]
AVAssetDownloadTask *avAssetVidDownloadTask = [avAssetDownloadSession assetDownloadTaskWithURLAsset:hlsAsset assetTitle:[NSString stringWithFormat:@"%@",assetName] assetArtworkData:nil options:nil];
if ([avAssetVidDownloadTask state] == NSURLSessionTaskStateSuspended) {
[avAssetVidDownloadTask resume];
}else{
[avAssetVidDownloadTask suspend];
}
} else {
// Fallback on earlier versions
}