mbhud进度条加上ASIHTTPRequest跟踪下载



我正在使用ASIHttpRequest和MB-HUD-progress库,现在我想显示MBHUD进度条下载视频文件。我混淆了这两个库的文档。

这是我的代码,我使用在应用程序购买库。我不知道如何实现以下方法的ASSiHttpRequest来引导我的下载与库

- (void) completeTransaction: (SKPaymentTransaction *)transaction
 {
NSLog(@"Transaction Completed");
// You can create a method to record the transaction.
// [self recordTransaction: transaction];
// You should make the update to your app based on what was purchased and inform user.
// [self provideContent: transaction.payment.productIdentifier];
// Finally, remove the transaction from the payment queue.
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
// Set determinate mode
HUD.mode = MBProgressHUDModeAnnularDeterminate;
//HUD.delegate = self;
HUD.labelText = @"Downloading";
// myProgressTask uses the HUD instance to update progress
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
[self downloadFromURL:[NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"]];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    }
   -(void)downloadFromURL:(NSURL *)url
     {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  filePath = [documentsDirectory stringByAppendingPathComponent:@"small.mp4"];
  NSLog(@"Path is %@",filePath);
  [request setDelegate:self];
  [request setTimeOutSeconds:60];
  [request setNumberOfTimesToRetryOnTimeout:2];
  [request setDownloadDestinationPath:filePath];
  [request startAsynchronous];
  [request setDownloadProgressDelegate:self];
   request.showAccurateProgress = YES;
  }

    - (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength
   {
    NSLog(@"newLength: %lld", newLength);
     }
    -(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes {
    NSLog(@"Received bytes:%lld",bytes);
       }
     -(void)requestFinished:(ASIHTTPRequest *)request
   {
 [MBProgressHUD hideHUDForView:self.view animated:YES];
 [self movieReceived];
    }
    -(void)requestFailed:(ASIHTTPRequest *)request
     { 
NSLog(@"%@",request.error);
    }

   -(void)movieReceived
      {
    playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
     }

 - (void)myProgressTask {
// This just increases the progress indicator in a loop
float progress = 0.0f;
while (progress < 1.0f) {
    progress += 0.01f;
    HUD.progress = progress;
    usleep(60000);
}
     }

我不知道如何改变我的进度任务的所有值来更新进度条根据文件的大小..

计算接收的字节数占

总字节数的百分比

-(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes

并设置进度值

HUD.progress = normalisedPercentage;

显示下载进度条

ASINetworkQueue *requestUserSpecificFileQueue = [[ASINetworkQueue alloc] init];
[requestUserSpecificFileQueue reset];
UIProgressView *progressView=[[UIProgressView alloc]initWithFrame:CGRectMake(5, 190, 200, 20)];
[ViewSelected addSubview:progressView];
[requestUserSpecificFileQueue setDownloadProgressDelegate:progressView];
[requestUserSpecificFileQueue setRequestDidFinishSelector:@selector(downLoadFinished:)];
[requestUserSpecificFileQueue setRequestDidFailSelector:@selector(downloadFailed:)];
[requestUserSpecificFileQueue setShowAccurateProgress:YES];
[requestUserSpecificFileQueue setDelegate:self];
ASIHTTPRequest *requestUserSpecificFile=[ASIHTTPRequest requestWithURL:[dict objectForKey:@"object"]];
requestUserSpecificFile.tag=bookViewSelected.tag;
[requestUserSpecificFile setDownloadDestinationPath:[[self returnUnzipBundlePathName] stringByAppendingPathComponent:dictLocal[@"fullLengthFilename"]]];

if __IPHONE_OS_VERSION_MAX_ALLOWED>= __IPHONE_4_0

[requestUserSpecificFile setShouldContinueWhenAppEntersBackground:YES];
<标题> endif h1> /html>

最新更新