ファイルのダウンロード サイズや合計サイズなどの機能を追加しましたが、このプロセスを完了するまでの残り時間を管理する方法がわかりません。誰か助けてくれませんか。
1 に答える
2
これまでの平均転送速度 (受信バイト数 / 経過時間) を計算し、それを残りのバイト数に適用することで、残り時間を見積もることができます。
Within your NSURLConnectionDelegate
's implementation of -connection:didReceiveResponse:
you'll want to record the time at which the transfer started and the expected size of the response (-[NSURLResponse expectedContentLength]
). Then as you receive chunks of data via -connection:didReceiveData:
you can keep track of the number of bytes of data received. That will give you sufficient information to estimate the time remaning as outlined above.
于 2013-01-20T01:04:40.333 に答える