我有一个使用AVAudioRecorder进行录制的应用程序。它的工作原理和保存音频文件就好了。但是当我重建应用程序时,音频文件将被删除。
这是正常的吗?我会这么想的,但只是想确定一下。我在网上找不到任何相关信息。每次进行新的构建时,Xcode是否会删除应用程序生成的任何新文件?
更新 我用来录制音频的代码如下:
// 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];
}
谢谢你的时间,Dan。