我正在从响应中下载视频文件。我想显示HUD-progress的下载进度条。但我该怎么做。我将验证 json 发送到服务器,服务器验证发送回视频文件字节。我想显示使用 HUD-progreasse 栏完成了多少百分比的下载。
如果我打电话[request setDidReceiveDataSelector:@selector(request:didReceiveBytes:)];
比它显示我得到了多少字节,但它不会将字节存储到缓存文件中(它不会将文件存储到手机中)
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[[NSURL alloc] initWithString:@"http://testing.io/dev.php/video/verifyReceipt"]];
[request setPostValue:resultAsString forKey:@"verify"];// sending json in post
[request setDidReceiveDataSelector:@selector(request:didReceiveBytes:)];
[request setDidFinishSelector:@selector(requestDone:)];
[request setTimeOutSeconds:120];
[request setDelegate:self];
[request setNumberOfTimesToRetryOnTimeout:2];
[request setDownloadProgressDelegate:self];
request.showAccurateProgress = YES;
[request startSynchronous];
}
-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
{
[videoData appendData:data];// appending data with global NSmutabledata
NSLog(@"data is %@",data);
}
- (void)requestDone:(ASIHTTPRequest *)request{
//[MBProgressHUD hideHUDForView:self.view animated:YES];
// SAVED Video PATH
// Get the Document directory
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your saved video location
NSString* movLocation = [documentDirectory stringByAppendingPathComponent:[fileName stringByAppendingString:@".mov"]];
if(request.responseStatusCode==200)
{
[videoData writeToFile:movLocation atomically:NO];
NSLog(@"in request done sucsessfully downlaod and store in database %d",request.responseStatusCode);
[DBHelper savePurchaseId:fileName];
[self movieReceived];
}
else{
NSLog(@"in request downlaod and store in database failed %@",request.responseHeaders);
}
}
-(void)requestFailed:(ASIHTTPRequest *)request
{
NSLog(@"%@",request.error);
}