title: How to save audio file after recording in iPhone?
body: <p>Hi I have code which dose recording, but I can not figure it out how to save and when I come back again then I can play same recorded file again?</p>
  
  <p>I am using below code for recording - </p>
  
  <pre><code>-----
  -(IBAction) 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];
  }
  
  NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", [[NSBundle mainBundle] resourcePath]]];
  
  
  NSError *error = nil;
  audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&amp;error];
  
  if ([audioRecorder prepareToRecord] == YES){
      [audioRecorder record];
  } else {
      int errorCode = CFSwapInt32HostToBig ([error code]); 
      NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&amp;errorCode); 
  
  }
  NSLog(@"recording");
  }
  ----
  </code></pre>
  
  <p>please let me know that how can i save this audio file? so i can re-open app again and play that recorded file.</p>
  
  <p>Thanks</p>