Question

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

the code above occasionally gives cocoa error 513 which is about permissions. I download files from internet placing in caches directory. Do I have to explicitly set some permissions or do something else? Why the error happens only sometimes? It never happens on 6.0/7.0, but happens sometimes on 7.1.

Was it helpful?

Solution

As I write in comment I guess the problem related to deleting some system files that not directly own by your app and should not be deleted.

for example how looks Cache folder in basic app with one UIWebView enter image description here

To avoid strange errors is better to create dedicated folder inside Library/Caches and delete content inside respected to your needs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top