在将 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);
}];
但是,“总单位数”似乎总是为 0,这意味着计算的完成百分比在整个除以 0 的情况下有点疯狂:
Video with ID 3 recording upload progress: inf, completed unit count 163922, total unit count 0
难道我做错了什么?遵循此处描述的文档。
[也在 Swift 中复制]