Best Practices zum Erstellen einer Warteschlange von NSURLSessionTasks

Was sind die besten Methoden für die Herstellung einer seriellen queue von NSURLSessionTasks ?

In meinem Fall brauche ich:

  1. Holen Sie sich eine URL innerhalb eines JSON-Datei (NSURLSessionDataTask)
  2. Die Datei herunterladen, URL (NSURLSessionDownloadTask)

Hier ist, was ich habe, so weit:

session = [NSURLSession sharedSession];

//Download the JSON:
NSURLRequest *dataRequest = [NSURLRequest requestWithURL:url];

NSURLSessionDataTask *task =
[session dataTaskWithRequest:dataRequest
           completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

               //Figure out the URL of the file I want to download:
               NSJSONSerialization *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
               NSURL *downloadURL = [NSURL urlWithString:[json objectForKey:@"download_url"]];

               NSURLSessionDownloadTask *fileDownloadTask =
               [session downloadTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:playlistURL]]
                              completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
                                  NSLog(@"completed!");
                              }];

               [fileDownloadTask resume];

           }
 ];

Abgesehen von der Tatsache, dass das schreiben einer Abschluss-block in einen anderen Abschluss sieht chaotisch, ich bin immer ein EXC_BAD_ACCESS Fehlermeldung, wenn ich call [fileDownloadTask resume]... obwohl fileDownloadTask ist nicht null!

Also, was ist der beste Weg, Sequenzierung NSURLSessionTasks?

Kommentar zu dem Problem
Für die Sequenzierung, wie etwa eine NSOperationQueue? Kommentarautor: Owen Hartnett

InformationsquelleAutor der Frage Eric | 2013-12-16

Schreibe einen Kommentar