Question

I am Making an Audio recorder(m4a extension files). I am Giving a particular URL for the output of the recorded File(in directory). I am able to play it, save the path of the file in database and can retrieve it later. EVery thing is going Fine. BUT I am not able to delete the saved/unsaved files. Every time I record an audio , the file is taking a permanent space. Am not able to delete them.

I tried it over internet(stackoverflow ofcourse). I got Links like this: I have video URL and want to delete it from the iPhone using this URl

But they are showing COCOA ERROR 4 when ever i try to delete them using codes like this: [[NSFileManager defaultManager] removeItemAtPath:strPath error:&error];

Please suggest, and reply

Was it helpful?

Solution 2

This is the path earlier i was getting , at which i was unable to write file

/var/mobile/Applications/8584F54E-75D2-4833-8826-29C125E53DBC/Library/Documentation/291013193758w.png

This morning, I just run my code once again ,. now its showing path

/var/mobile/Applications/DDA14123-6A88-4756-B2E4-C4A3AA39AA5B/Documents/291013081335test.png

on this path am able to write my file

the Difference between two paths is that, first one is of Library/Documentation , where as second one is of Documents

dont know the difference, but it is working now

OTHER TIPS

You typically accomplish this for resources you've saved in your Apps documents directory like this:

unlink([pathForURL UTF8String]);

where pathForURL is an NSString that describes the path to the resource you're deleting.

There may be case that file path which you provide is not correct. If its correct then try following with URL, it might solve your issue

NSString *str= [outputFieldURL absoluteString];

    NSError *error;

    NSURL *url = [NSURL URLWithString:str];
    BOOL success = [[NSFileManager defaultManager] removeItemAtURL:url error:&error];


    if (!success) {
        NSLog(@"Error removing file at path: %@", error.localizedDescription);
    }
    else
    {
        NSLog(@"File removed  at path: %@", error.localizedDescription);
    }
}

Before deleting the file you have to check file there or not :

 NSFileManager* manager = [[NSFileManager alloc] init];
 if ([manager fileExistsAtPath:path]) {
    [manager removeItemAtPath:path error:&error];
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top