2012-02-15 4 views
1

녹음 된 파일을 내 앱 문서에 저장하고 싶지만 어떻게해야하는지 알 수 없습니다. 녹음을했고 임시 파일에 저장되어있어 그 사운드를 재생할 수 있습니다. 이제 그 파일을 새로운 이름으로 저장하고 싶습니다.iOS - 앱 문서에 기록 저장

NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *docsDir = [dirPaths objectAtIndex:0]; 
NSString *soundFilePath = [docsDir 
           stringByAppendingPathComponent:@"tmpSound.caf"]; 

tempRecFile = [NSURL fileURLWithPath:soundFilePath]; 

NSDictionary *recSettings = [NSDictionary 
            dictionaryWithObjectsAndKeys: 
            [NSNumber numberWithInt:AVAudioQualityMin], 
            AVEncoderAudioQualityKey, 
            [NSNumber numberWithInt:16], 
            AVEncoderBitRateKey, 
            [NSNumber numberWithInt: 2], 
            AVNumberOfChannelsKey, 
            [NSNumber numberWithFloat:44100.0], 
            AVSampleRateKey, 
            nil]; 

recorder = [[AVAudioRecorder alloc] initWithURL:tempRecFile settings:recSettings error:nil]; 
[recorder setDelegate:self]; 
[recorder prepareToRecord]; 
[recorder record]; 

이 어떻게 해야할지 중 하나를 수행하거나이 작업을 수행하는 경우에도 가능하다면 :

코드는 사운드를 녹음하기 위해?

답변

1

당신은 같은 것을 사용하여이 작업을 수행 할 수 있어야한다

[[NSFileManager defaultManager] copyItemAtURL:tempRecFile toURL:newURL error:nil]; 

그러나 경고의 말씀 - 당신은 신중하게 생각해야 이 오디오를 문서 폴더에 실제로 저장해야하는지 캐시 폴더가 충분한 지 여부에 관계없이 Apple은 허용되는 것에 대해 엄격한 규칙을 가지고 있습니다.

1

NSFileManager을 사용하여 파일을 이동하십시오. 당신이 오류에 대한 상관하지 않는 경우

NSError *error; 
[[NSFileManager defaultManager] copyItemAtURL:tempRecFile toURL:newURL error:&error]; 

또는 :