Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
每次重建应用程序时删除的AVRecorder文件-iOS_Ios_Xcode_Avfoundation_Avaudiorecorder_Recording - Fatal编程技术网

每次重建应用程序时删除的AVRecorder文件-iOS

每次重建应用程序时删除的AVRecorder文件-iOS,ios,xcode,avfoundation,avaudiorecorder,recording,Ios,Xcode,Avfoundation,Avaudiorecorder,Recording,我有一个使用AVAudioRecorder进行录音的应用程序。它可以正常工作并保存音频文件。但当我重建应用程序时,音频文件会被删除 这正常吗?我本来会这么想,但我只是想确定一下。我在网上找不到关于这个的任何信息。每次生成新版本时,Xcode是否会删除应用程序生成的任何新文件 更新 我用来录制音频的代码如下: // Setup audio recorder to save file. AVAudioSession *audioSession = [AVAudioSession sh

我有一个使用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];
   }

谢谢您的时间,丹。

简短回答,不。您必须使用模拟器上的重置内容和设置来完成此操作。向我们展示您用来保存音频文件的代码。@GlennRay很抱歉我的回复太晚了。我已经用我用来录制音频的代码更新了我的问题。所以我现在的做法似乎只是将音频文件保存在一个特定的版本中。每次我更新构建时,音频文件都会被删除,这是否意味着在应用商店更新中,用户会丢失所有音频文件??因此,如果构建没有更改,这些文件将被保存并可播放?@GlennRay是的,这是正确的。我一更新构建,它就好像被删除了。我想知道NSSearchPathForDirectoriesInDomains是否是问题所在。根据文档,通过这种方法找到的目录实际上可能不存在。另外,您应该考虑使用NSLMeMeNeFrice方法URLSFordBudio:IdMauns:UrLFordStord:DuffMa:OpjeToFr:URL:CREATE:Error:。返回URL,这是首选格式。。