0

I have an app which makes recordings using AVAudioRecorder. Its works and saves the audio files just fine. But when I rebuild the app, the audio files are deleted.

Is that normal? I would have thought so, but just wanted to make sure. I can't find anything about this online. Does Xcode delete any new files made by the app, each time a new build is made?

UPDATE The code I am using to record the audio is as follows:

    // Setup audio recorder to save file.
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    [audioSession setActive:YES error:nil];
    [audio_recorder setDelegate:self];

    // Set the recording options such as quality.
    NSMutableDictionary *settings = [NSMutableDictionary dictionary];
    [settings setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
    [settings setValue:[NSNumber numberWithFloat:8000.0] forKey:AVSampleRateKey];
    [settings setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
    [settings setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
    [settings setValue:[NSNumber numberWithInt:AVAudioQualityMax] forKey:AVEncoderAudioQualityKey];

    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath_ = [searchPaths objectAtIndex:0];
    NSString *pathToSave = [documentPath_ stringByAppendingPathComponent:currentDate];

    // Construct the audio file save URL.
    NSURL *url = [NSURL fileURLWithPath:pathToSave];

    // Setup the audio recorder.
    NSError *error;
    audio_recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];

    if (error == nil) {

        // Now begin the recording.
        [audio_recorder prepareToRecord];
        [audio_recorder record];
   }

Thanks for your time, Dan.

Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98
  • Short answer, no. You have to use `Reset Contents and Settings` on the Simulator to do that. Show us the code you're using to save the audio files. – GlennRay Feb 23 '15 at 23:12
  • @GlennRay SOrry for my late reply. I have updated my question with the code I am using to record audio. So the way I am doing it only seems to save the audio files in a particular build. Everytime I update the build the audio files are deleted, does this mean that in an App Store update, the user will loose all of their audio files?? – Supertecnoboff Feb 26 '15 at 06:45
  • So the files are saved and playable if the build doesn't change? – GlennRay Feb 26 '15 at 23:18
  • @GlennRay Yes that is correct. As soon as I update the build it seems to delete. – Supertecnoboff Feb 27 '15 at 06:45
  • I'm wondering if `NSSearchPathForDirectoriesInDomains` might be the problem. According to the documentation, the directories found by this method may not actually exist. Also: `You should consider using the NSFileManager methods URLsForDirectory:inDomains: and URLForDirectory:inDomain:appropriateForURL:create:error:. which return URLs, which are the preferred format.`. – GlennRay Feb 27 '15 at 20:34
  • From the info in this question (http://stackoverflow.com/questions/23278735/null-when-using-fopen-with-xcode/23279783#23279783), I wonder if the actual name of the directory changes with each build. When saving the audio files, can you try using an absolute path? Or at least see what the path is when you save? – GlennRay Mar 05 '15 at 01:33
  • @Supertecnoboff This SO post may be useful: http://stackoverflow.com/questions/12135687/record-audio-file-and-save-locally-on-iphone –  May 12 '15 at 10:35

0 Answers0