I am using AFNetworking to download an mp3 file. The download happens in a particular ViewController. Since the mp3 file is quite large, it takes a few minutes to complete the download. The problem is that when i go to another ViewController, the download stops and i have to stay on the download ViewController and wait for the download to complete. That would be frustrating for the user! Is there a way to get the download going even when the download ViewController is dismissed? Here is the code i use for downloading:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.sample.com/samplefile.mp3"]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSString *mp3Name = @"sample.mp3";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:mp3Name];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];