在 Apple 平台上使用 Cloud Storage 刪除文件

將檔案上傳到雲端儲存後,您也可以刪除它們。

刪除文件

若要刪除文件,請先建立對該文件的引用。然後對該引用呼叫deleteWithCompletion:方法。

迅速

// 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
  }
}];
    

處理錯誤

文件刪除時可能發生錯誤的原因有很多,包括文件不存在,或是使用者沒有刪除所需文件的權限。有關錯誤的更多資訊可以在文件的處理錯誤部分找到。