iOS アプリ内で録画した動画ファイルを Firebase にアップロードするときにプログレス バーをユーザーに表示したいのでobserveStatus
、SDK の機能を使用しています。
// Create a root reference
FIRStorageReference *storageRef = [_storage reference];
// Create a reference to the video
FIRStorageReference *videoRef = [storageRef child:uuidString];
// Upload the file
FIRStorageUploadTask* uploadTask = [videoRef putFile:url metadata:nil];
[uploadTask observeStatus:FIRStorageTaskStatusProgress handler:^(FIRStorageTaskSnapshot *snapshot) {
// A progress event occurred
double percentComplete = 100.0 * (snapshot.progress.completedUnitCount) / (snapshot.progress.totalUnitCount);
NSLog(@"Video with ID %d recording upload progress: %f, completed unit count %lld, total unit count %lld", video.videoId, percentComplete, snapshot.progress.completedUnitCount, snapshot.progress.totalUnitCount);
}];
ただし、「Total Unit Count」は常に 0 のように見えます。つまり、計算された完了率は、0 による除算の状況全体で少しおかしくなります。
Video with ID 3 recording upload progress: inf, completed unit count 163922, total unit count 0
私は何か間違ったことをしていますか?ここで説明されているドキュメントに従ってください。
【Swiftにも再現】