0

NSURLConnection を使用して URL からファイルをダウンロードするアプリケーションが 1 つあります。ボタンのダウンロードをクリックするときに、progressViewが開始するタイミングが必要です。progressView の一番上にある UILable は、ステータスのダウンロードを表示します。UILable で ("0000 MB ダウンロード /1000 MB") を表示したい。最初の部分はダウンロードされたファイルの量で、2 番目の部分はファイルのサイズです。どのように表示するかわかりません。プログレスビューで動作する(ダウンロードされた量/サイズのファイル)をどのように表示するか教えてください。

ありがとう。

4

2 に答える 2

0

AFNetworkingを使用している場合

ここで progress は、ダウンロードの進行状況を表示するための UIProgressbar です

 progress.progress = 0.0;

    currentURL=@"http://www.selab.isti.cnr.it/ws-mate/example.pdf";


    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]];
    AFURLConnectionOperation *operation =   [[AFHTTPRequestOperation alloc] initWithRequest:request];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"MY_FILENAME_WITH_EXTENTION.pdf"];
    operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];

    [operation setDownloadProgressBlock:^(NSInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {
        progress.progress = (float)totalBytesRead / totalBytesExpectedToRead;

    }];

    [operation setCompletionBlock:^{
        NSLog(@"downloadComplete!");

    }];
    [operation start];
于 2013-05-08T11:56:53.643 に答える