我是iOS应用程序开发平台的新手,我正在寻找上一个星期的一件事,实际上我的要求是我有一个UITableview
的网址很少,而且didselectRowAtIndexPath
该歌应该是在后台运行,下载进度显示在另一个选项卡中。
当我点击多个按钮时,会同时下载多首歌曲,并且所有下载进度都会在下一个标签中单独显示,这里我很乐意暂停,恢复和取消特定下载。这是我的要求。我使用AFNetworking但它不清楚请帮助我做必要的事情。 我的AFNetworking代码
NSURL *url = [NSURL URLWithString:downLoadedUrlParam];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:3600];
NSString *MUSICFile=[DocumentsDirectory stringByAppendingPathComponent:songName];
self.operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:MUSICFile shouldResume:YES];
[self.operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", MUSICFile);
//[ProcessingUrlsArray removeObject:videoString];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
if(operation.response.statusCode!= 200) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Error While Downloaded" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}];
[httpClient enqueueHTTPRequestOperation:self.operation];
[self.operation setProgressiveDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
float percentDone = totalBytesReadForFile/(float)totalBytesExpectedToReadForFile;
NSLog(@"------%@",[NSString stringWithFormat:@"CUR : %lli M",totalBytesReadForFile/1024/1024]);
NSLog(@"------%@",[NSString stringWithFormat:@"TOTAL : %lli M",totalBytesExpectedToReadForFile/1024/1024]);
NSLog(@"------%f",percentDone);
NSLog(@"------%.0f%%",percentDone*100);
self.myProgressBar.progress=percentDone;
NSLog(@"Operation%i: bytesRead: %d", 1, bytesRead);
NSLog(@"Operation%i: totalBytesRead: %lld", 1, totalBytesRead);
NSLog(@"Operation%i: totalBytesExpected: %lld", 1, totalBytesExpected);
NSLog(@"Operation%i: totalBytesReadForFile: %lld", 1, totalBytesReadForFile);
NSLog(@"Operation%i: totalBytesExpectedToReadForFile: %lld", 1, totalBytesExpectedToReadForFile);
NSLog(@"%@",downLoadedUrlParam);
self.title=downLoadNameParam;
NSMutableArray *stgPerst;
stgPerst=[[NSMutableArray alloc]initWithCapacity:0];
NSDictionary *dicInfo=[NSDictionary dictionaryWithObjects:@[[NSString stringWithFormat:@"%f",percentDone],downLoadNameParam] forKeys:@[@"heProg",@"heName"]];
NSLog(@"dict=%@",dicInfo);
[[NSNotificationCenter defaultCenter] postNotificationName:@"DOWNLOAD_PROGRESS" object:nil userInfo:dicInfo];
}];