0

私は、AsiHttpRequest でダウンロードの進行状況を次のように表示しようとしています: 300 kb / 5 Mb で、常に最初の値を更新します。-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data を使用する場合、自分で nsdata オブジェクトを管理し、ダウンロードしたファイルを自分で書き込む必要があることを理解しました

私はこれを試しましたが、うまくいきません!! 変更可能なデータが null です! 私はARCでiOS 5を使用しています。助けてくれてありがとう!

更新しました

このコードで解決しました。デリゲートを自分自身に設定すると、すべてが正しく機能します。この方法でARCを使用してデリゲートをクリアする必要があるかどうかはわかりません

- (void)dealloc
{
   [request clearDelegatesAndCancel];
}

助けてくれてありがとう!

更新しました

-(void)downloadFile: (NSString*) file {
           NSString* urlFilePdf = [NSString stringWithFormat:@"http://www.mywebsite.com/%@",file];

            myFileName = file;

            NSURL *url = [NSURL URLWithString:urlFilePdf];

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *filePath = [documentsDirectory stringByAppendingPathComponent:file];


            progressAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DOWNLOADFILE",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];

            progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
            [progressAlert addSubview:progressView];
            [progressView setProgressViewStyle: UIProgressViewStyleDefault];

            lblTotal = [[UILabel alloc] initWithFrame:CGRectMake(5, 50, 273, 20)];
            [lblTotal setTextAlignment:UITextAlignmentCenter];
            [lblTotal setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:14.0]];
            [lblTotal setTextColor:[UIColor whiteColor]];
            [lblTotal setBackgroundColor:[UIColor clearColor]];
            [progressAlert addSubview:lblTotal];

            requestFile = [ASIHTTPRequest requestWithURL:url];
            [requestFile setDelegate:self];
            [requestFile setDownloadDestinationPath:filePath];
            [requestFile setDownloadProgressDelegate:self];
            [requestFile setShowAccurateProgress:YES];    
            [progressAlert show];

            [requestFile startAsynchronous];

}

- (void)request:(ASIHTTPRequest *)request incrementDownloadSizeBy:(long long)newLength
{
    NSLog(@"%@",[NSString stringWithFormat:@"incrementDownloadSizeBy %quKb", newLength/1024]);
}

- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
{
    NSLog(@"%@",[NSString stringWithFormat:@"didReceiveBytes %quKb", bytes/1024]);
    currentLength += bytes;
    [lblTotal setText:[NSString    stringWithFormat:@"%quKb/%@",currentLength/1024,self.TotalFileDimension]];
}

- (void)setProgress:(float)newProgress {
    NSLog(@"%f",newProgress);
    progressView.progress = newProgress;
}


-(void) requestFinished:(ASIHTTPRequest *)request
{
    // code ...
}

-(void) requestFailed:(ASIHTTPRequest *)request
{
    // code ...
}

- (void)dealloc
{
   [request clearDelegatesAndCancel];
}
4

1 に答える 1

0

メソッドを実装する必要がありますrequest:incrementDownloadSizeBy:

注意: あなたが書いた質問のタイトルはiOS Asihttprequest custom progress trackingです。ASIHTTPRequest のドキュメントを見ると、何を求めているのかを正確に説明する見出しが表示されます -カスタム進行状況追跡

これを見ていない場合、それは大きな問題です。人に助けを求める前に、必ずドキュメントを確認してください。

于 2012-05-03T18:08:47.560 に答える