I have to download file from server on respective button click in UITableViewCell.When user taps Button to download in one cell download should be started.After completion of downloading I'm saving in core data.Up to this All went well.But while downloading current file if user taps to download another file in Cell it also should download then save to core data and make available to play.And i have different url's in each table cell.If user taps multiple buttons should download them and save to core data.Here my code.
NSString *url=[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"voice"];
NSLog(@"%@",url);
//NSURL *voiceUrl=[NSURL URLWithString:url];
tempDict=[[NSMutableDictionary alloc]init];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"msg_id"] forKey:@"msg_id"];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"to"] forKey:@"to"];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"from"] forKey:@"from"];
[tempDict setValue:[[chatHistoryArr objectAtIndex:sender.tag]valueForKey:@"time"] forKey:@"time"];
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:cell.playButton.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"], nil];
animatedImageView.animationDuration = 3.0f;
animatedImageView.animationRepeatCount = 10;
[animatedImageView startAnimating];
[cell1.playButton addSubview: animatedImageView];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
[manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/octet-stream",@"video/3gpp",@"audio/mp4",nil];
NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error)
{
NSLog(@"Error: %@", error);
} else
{
NSData *data=[[NSData alloc]initWithData:responseObject];
//Here I'm saving file to local storage then updating UI.
[self sentMsgSaveWithData:data orUrl:@"" withBool:YES withMsg_ID:@"" withDict:tempDict];
}
}];
[dataTask resume];
Here I managed to download only one file at a time and after completion of that if user taps another cell then only I'm downloading it.But I have to download multiple files on multiple button taps in Cell.
I have been struggling lot to implement this.Please give some suggestions.
Thanks in advance.