簡體   English   中英

刪除文件時偶爾出現錯誤

[英]Occasional error while deleting files

NSFileManager *fileMgr = [[NSFileManager alloc] init];
NSError *error = nil;

NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [fileMgr contentsOfDirectoryAtPath:cachePath error:nil];

for (NSString *path in files)
{
    NSString *fullPath = [cachePath stringByAppendingPathComponent:path];
    BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error];
    if (!removeSuccess)
    {
        return error;
    }
}

上面的代碼有時會給出與權限有關的可可錯誤513。 我從放置在緩存目錄中的Internet下載文件。 我是否必須明確設置一些權限或執行其他操作? 為什么錯誤僅在某些時候發生? 它永遠不會在6.0 / 7.0上發生,但有時會在7.1上發生。

當我在評論中寫道時,我猜想與刪除一些不是您的應用程序直接擁有的系統文件有關的問題,因此不應刪除。

例如,如何使用一個UIWebView在基本應用程序中查找Cache文件夾 在此處輸入圖片說明

為了避免出現奇怪的錯誤,最好在“ Library/Caches創建專用文件夾,並根據需要刪除其中的內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM