找不到 iPhone 模拟器生成的文件

Posted

技术标签:

【中文标题】找不到 iPhone 模拟器生成的文件【英文标题】:Cannot find file generated by iPhone simulator 【发布时间】:2011-04-14 10:36:27 【问题描述】:

如果这与 my previous question 重复,我深表歉意,但这让我有点生气。

为了找出 iPhone 模拟器存储文件的位置,我使用 Speak Here 项目来录制我的声音并将其保存到文件中。由于模拟器能够播放录音必须在某处有一个文件,但我无法找到。我已经尝试了所有方法,包括使用终端命令 locate(在使用 sudo /usr/libexec/locate.updatedb 之后)。有什么帮助吗?

【问题讨论】:

【参考方案1】:

SpeakHere 应用程序将录制的文件存储在临时目录中。您可以使用以下代码找出路径及其内容:

    NSString *tempPath = NSTemporaryDirectory();
    NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tempPath error:nil];
    NSLog(@"tempPath: %@", tempPath);
    NSLog(@"dirContents: %@", dirContents);

ios 模拟器中,这条路径类似于 /var/folders/eQ/eQdXXQoxFHmxhq85pgNA+++++TI/-Tmp-/ 但在设备上,这是您的应用程序目录中的子目录。喜欢/private/var/mobile/Applications/965A9EEF-7FBA-40F4-8A42-FE855A719D52/tmp/

【讨论】:

【参考方案2】:

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]

-(void) startRecording [自动停止播放];

NSLog(@"startRecording");
[audioRecorder release];
audioRecorder = nil;

// Init audio with record capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];

NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
if(recordEncoding == ENC_PCM)

    [recordSettings setObject:[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
    [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
    [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];   

else

    NSNumber *formatObject;

    switch (recordEncoding) 
        case (ENC_AAC): 
            formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC];
            break;
        case (ENC_ALAC):
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleLossless];
            break;
        case (ENC_IMA4):
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
            break;
        case (ENC_ILBC):
            formatObject = [NSNumber numberWithInt: kAudioFormatiLBC];
            break;
        case (ENC_ULAW):
            formatObject = [NSNumber numberWithInt: kAudioFormatULaw];
            break;
        default:
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
    

    [recordSettings setObject:formatObject forKey: AVFormatIDKey];
    [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
    [recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];


NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSInteger
NSInteger recordID = [prefs integerForKey:@"recordID"];
//NSLog(@"---- %d",recordID);

//NSString *recordFileName = [NSString stringWithFormat:@"%@/record%d.caf", [[NSBundle mainBundle] resourcePath], recordID];
NSString *recordFileName = [NSString stringWithFormat:@"%@/record%d.caf", DOCUMENTS_FOLDER, recordID];

NSURL *url = [NSURL fileURLWithPath:recordFileName];

//NSLog(@"path -- %@",DOCUMENTS_FOLDER);

NSError *error = nil;
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];

if ([audioRecorder prepareToRecord] == YES)
    [audioRecorder record];
else 
    int errorCode = CFSwapInt32HostToBig ([error code]); 
    NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode);

NSLog(@"recording");

[recordSettings release];

-(void) 停止录制 NSLog(@"stopRecording"); [录音机停止]; NSLog(@"停止");

【讨论】:

AudioFileURLCreateWithURL 错误 -50 我在参考中找不到:developer.apple.com/library/ios/#documentation/MusicAudio/…

以上是关于找不到 iPhone 模拟器生成的文件的主要内容,如果未能解决你的问题,请参考以下文章

Xcode 11 beta 上找不到 iPhone 7 模拟器

`react-native run-ios` 返回错误:找不到 iPhone X 模拟器

react-native run-ios 找不到 iPhone X 模拟器 | XRPackageModel 9.0.omo

在我的开发环境中找不到 Plist 文件

iPhone模拟器中缺少一些文件夹?

dyld:库未加载...原因:找不到合适的图像 Xcode Swift