מחק קבצים עם Cloud Storage בפלטפורמות של 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
  }
}];
    

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

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