將檔案上傳至 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 } }];
處理錯誤
檔案刪除發生錯誤的可能原因有很多, 包含檔案不存在,或使用者沒有權限 刪除所需檔案如要進一步瞭解錯誤,請前往 處理錯誤 一節。