7

約 10 個の異なる大きなファイルをキューにダウンロードする必要があり、転送全体のステータスを示す進行状況バーを表示する必要があるという問題に取り組んでいます。これは iOS4 の ASIHTTPRequest で問題なく動作していますが、iOS5 では ASIHTTPRequest に問題があり、維持されなくなったため、AFNetworking に移行しようとしています。

AFHTTPRequestOperation の downloadProgressBlock を使用して個々のリクエストの進行状況を報告できることは知っていますが、同じ NSOperationQueue で実行される複数のリクエストの全体的な進行状況を報告する方法が見つからないようです。

助言がありますか?ありがとう!

4

3 に答える 3

1
[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
    NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];

Operation is AFHTTPRequestOperation

于 2011-12-20T09:29:49.150 に答える
0

UIProgressViewを、監視しているすべての異なるアイテムを追跡し、それらの進行状況をすべて一緒に追加するロジックを持つサブクラスでサブクラス化してみます。

おそらくこのようなコードで:

 @implementation customUIProgressView

-(void) updateItem:(int) itemNum ToPercent:(NSNumber *) percentDoneOnItem {
  [self.progressQueue  itemAtIndexPath:itemNum] = percentDoneOnItem;

  [self updateProgress];
}
-(void) updateProgress {
  float tempProgress = 0;
  for (int i=1; i <= [self.progressQueue count]; i++) {
    tempProgress += [[self.progressQueue  itemAtIndexPath:itemNum] floatValue];
  }
  self.progress = tempProgress / [self.progressQueue count];
}
于 2011-11-27T23:10:47.767 に答える
0

AFURLConnectionOperation をサブクラス化して(NSInteger)totalBytesSent、 と の2 つの新しいプロパティを持つことができ(NSInteger)totalBytesExpectedToSendます。これらのプロパティを NSURLConnection コールバックで次のように設定する必要があります。

- (void)connection:(NSURLConnection *)__unused connection 
   didSendBodyData:(NSInteger)bytesWritten 
 totalBytesWritten:(NSInteger)totalBytesWritten 
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    [super connection: connection didSendBodyData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
    self.totalBytesSent = totalBytesWritten;
    self.totalBytesExpectedToSend = totalBytesExpectedToSend;
}

uploadProgress ブロックは次のようになります。

……(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
    NSInteger queueTotalExpected = 0;
    NSInteger queueTotalSent     = 0;
    for (AFURLConnectionOperation *operation in self.operationQueue) {
        queueTotalExpected += operation.totalBytesExpectedToSend;
        queueTotalSent     += operation.totalBytesSent;
    }
    self.totalProgress = (double)queueTotalSent/(double)queueTotalExpected;
}];
于 2011-11-28T04:04:59.817 に答える