我正在使用 ASIHTTPRequest 在后台从 URL 下载视频文件。
我正在显示带有进度条和百分比的下载,我希望用户可以控制下载,例如暂停和恢复。
下面是代码:
-(void)Initiate_Download:(NSString*)urlStr contentID:(NSString*)cid progressBar:(UIProgressView*)progressBar
{
NSLog(@"Initiate_Download for cid:%@",cid);
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlStr]];
NSString *fileName = [NSString stringWithFormat:@"%@.mp4",cid];
NSString *destinationPath = [[self VideoDownloadFolderPath]stringByAppendingPathComponent:fileName];
[request setDownloadDestinationPath:destinationPath];
[request setTemporaryFileDownloadPath:[NSString stringWithFormat:@"%@-part",destinationPath]];
[request setDelegate:self];
NSDictionary *rqstDict = [NSDictionary dictionaryWithObjectsAndKeys:cid,@"cid",urlStr,@"url", nil];
[request setUserInfo:rqstDict];
[request setAllowResumeForFileDownloads:YES];
[request startAsynchronous];
}
//Delegate
- (void)requestStarted:(ASIHTTPRequest *)request1
{
//some code
}
- (void)request:(ASIHTTPRequest *)request1 didReceiveResponseHeaders:(NSDictionary *)responseHeaders
{
//some code
}
- (void)requestFinished:(ASIHTTPRequest *)request1
{
//some code
}
- (void)requestFailed:(ASIHTTPRequest *)request1
{
//some code
}