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

时间:2011-04-14 10:36:27

标签: iphone cocoa-touch file filesystems simulator

如果这与my previous question重复,我表示道歉,但这让我感到有些麻烦。

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

2 个答案:

答案 0 :(得分:0)

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-/但在设备上,这是app dir中的子目录。比如/private/var/mobile/Applications/965A9EEF-7FBA-40F4-8A42-FE855A719D52/tmp/

答案 1 :(得分:-1)

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

- (void)startRecording {     [self stopPlaying];

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)stopRecording {     的NSLog(@ “stopRecording”);     [audioRecorder stop];     的NSLog(@ “停止”); }