将文件上传至 Cloud Storage 后,您还可以删除它们。
删除文件
如需删除某个文件,请先为该文件创建引用。然后,对该引用调用 deleteWithCompletion:
方法。
Swift
// Create a reference to the file to delete let desertRef = storageRef.child("desert.jpg") do { // Delete the file try await desertRef.delete() } catch { // ... }
Objective-C
// Create a reference to the file to delete FIRStorageReference *desertRef = [storageRef child:@"images/desert.jpg"]; // Delete the file [desertRef deleteWithCompletion:^(NSError *error){ if (error != nil) { // Uh-oh, an error occurred! } else { // File deleted successfully } }];
处理错误
导致删除文件时出错的原因有很多,包括文件不存在,或者用户不具备删除相应文件的权限。如需详细了解这些错误,请参阅文档的处理错误部分。