我从 2 天开始就卡住了,我想显示下载进度条。我将 json 邮寄到服务器,作为响应服务器向我发送视频数据。为了显示进度条,我编写了一些逻辑代码,例如
在didreceivedata
方法中,ASIhttep
我将接收数据附加到全局NSmutabledata
,在请求完成方法中,我将该全局Nsmutalbedata
写入文件。但文件是空白的,它不会存储到文件中。
我知道 ASIHttprequest 是旧库,但每个人都建议我使用 AFnetworking,但我不想更改代码,因为这需要很长时间,而且我必须再次阅读文档。
任何人都可以帮助我如何附加数据并在下载完成后将附加的数据写入文件?
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[[NSURL alloc] initWithString:@"http://testing.io/dev.php/video/verifyReceipt"]];
[request setDidReceiveDataSelector:@selector(request:didReceiveData:)];
[request setPostValue:resultAsString forKey:@"verify"];
[request setDidFinishSelector:@selector(requestDone:)];
[request setTimeOutSeconds:120];
[request setDelegate:self];
[request setNumberOfTimesToRetryOnTimeout:2];
[request setDownloadProgressDelegate:progressBar];
request.showAccurateProgress = YES;
[request startSynchronous];
}
-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
{
[videoData appendData:data];
NSLog(@"data is %@",data);
}
- (void)requestDone:(ASIHTTPRequest *)request
{
//[MBProgressHUD hideHUDForView:self.view animated:YES];
// SAVED PDF PATH
// Get the Document directory
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your saved pdf 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);
}
}