1 Reply
      Latest reply on Mar 13, 2019 7:09 AM by ios-dev-br
      ASukhov Level 1 Level 1 (0 points)

        I try to download two HLS asset simultaneously in background. After the first task completed, iOS killed application, because application did not call completionHandler for background session. iOS call handleEventsForBackgroundURLSession for each AVAggregateAssetDownloadTask with some different identifiers. How can i download a few AVAggregateAssetDownloadTask at the same time in background?

         

        Step to reproduce:

        1) Create AVAssetDownloadURLSession session

        
            NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"some.id"];
            configuration.networkServiceType = NSURLNetworkServiceTypeBackground;
            configuration.allowsCellularAccess = NO;
        [AVAssetDownloadURLSession sessionWithConfiguration:configuration
                                          assetDownloadDelegate:self
                                                delegateQueue:nil]
        
        

         

        2) Create two AVAggregateAssetDownloadTask task:

        AVAggregateAssetDownloadTask *task = [self.urlSession aggregateAssetDownloadTaskWithURLAsset:avAsset
                  mediaSelections:mediaSelections
                  assetTitle:@"title"
                  assetArtworkData:artworkData
                  options:nil];
        [task resume];
        

         

        3) Transfer app to background

        4) Wait for callback from iOS

        - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler{
             NSLog(@"%@", identifier);
        }
        
        

         

        Result:

        some.id.2.childAssetDownloadTasks

         

        iOS create new background NSURLSession for each AVAggregateAssetDownloadTask.