0

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

Community
  • 1
  • 1
Jasmeet
  • 1,522
  • 2
  • 22
  • 41

3 Answers3

0

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.

ryan cumley
  • 1,901
  • 14
  • 11
  • hi Ryan, I followed what u said in above comment, but failed once again. i have added above something. please have a look , and help. I shall be thankful to you. – Jasmeet Oct 30 '13 at 07:29
0

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];
 }
Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56
  • yeah the problem was of path, I have added my answer, its working now. But dont know the exact answer. – Jasmeet Oct 31 '13 at 06:45
0

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

Jasmeet
  • 1,522
  • 2
  • 22
  • 41