מחיקת קבצים באמצעות Cloud Storage בפלטפורמות של Apple

אחרי שמעלים קבצים ל-Cloud Storage, אפשר גם למחוק אותם.

מחיקת קובץ

כדי למחוק קובץ, קודם צריך ליצור הפניה לקובץ הזה. אחר כך קוראים ל-method‏ 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
  }
}];
    

טיפול בשגיאות

יכולות להיות כמה סיבות לשגיאות במחיקת קבצים, כולל העובדה שהקובץ לא קיים או שלמשתמש אין הרשאה למחוק את הקובץ שצוין. מידע נוסף על שגיאות זמין בקטע טיפול בשגיאות במסמכים.