Xoá tệp bằng Cloud Storage trên các nền tảng của Apple

Sau khi tải tệp lên Cloud Storage, bạn cũng có thể xoá những tệp đó.

Xoá tệp

Để xoá một tệp, trước tiên, hãy tạo tệp tham chiếu đến tệp đó. Sau đó, hãy gọi phương thức deleteWithCompletion: trên tham chiếu đó.

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

Xử lý lỗi

Có một số lý do có thể khiến lỗi xảy ra khi xoá tệp, bao gồm cả khi tệp không tồn tại hoặc người dùng không có quyền xoá tệp mong muốn. Bạn có thể xem thêm thông tin về lỗi trong phần Xử lý lỗi của tài liệu.