title: problem with audioRecorderDidFinishRecording: successfully:
body: <p>I am facing this problem:</p>
  
  <p>I record some audio using the iPhone microphone and upload it to my server. I <code>record</code> for say, 40 seconds and call the <code>upload</code> function after 41 seconds (timer). Now, the recorded file that is uploaded to the server is not the full file since the function     </p>
  
  <pre><code>audioRecorderDidFinishRecording:  successfully:  
  </code></pre>
  
  <p>is not called before I call the <code>upload</code> function. Its called only after the <code>upload</code> function is called - no matter when I call the <code>upload</code> function - 10 seconds later or 100 seconds later. </p>
  
  <p>In the upload function, I use ASIHTTPRequest and ASIFormDataRequest to upload the file.</p>
  
  <p>Can anyone kindly tell me why this is happening ? Thanks.</p>
  
  <p>Edit #1:
  If the  <code>upload</code> method is not called, the <code>audioRecorderDidFinishRecording: successfully:</code> method is never invoked. Pretty strange !</p>
  
  <p>Edit #2:</p>
  
  <p>Relevant methods: </p>
  
  <pre><code>(void) upload
  {
  
  
  NSString *urlString = @"&lt;SOME_LINK&gt;";
  NSURL *url=[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];  
  ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
  
  NSData *fileData=[NSData dataWithContentsOfURL:recordedTmpFile];
  [request setData:fileData withFileName:[fileName copy] andContentType:@"audio/x-caf" forKey:@"userfile"];
  [request setPostValue:[appDelegate getRandomXML] forKey:@"random"];
  [request setRequestMethod:@"POST"];
  [request setDelegate:self];
  
  
  
  [request setShouldContinueWhenAppEntersBackground:YES];
  [request startSynchronous];
  
  }
  
  
  
  
  - (void) record
  {
  NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
  [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];
  [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
  [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
  
  NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
  [formatter setDateFormat:@"hh:mm:ss"];
  NSString *dateString=[formatter stringFromDate:[NSDate date]];
  
  fileName=[@"recordTest" stringByAppendingFormat:@"%@.alac", dateString];
  
  [formatter release];
  
  
  NSString *documentDirectory=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  
  NSString *mediaPath=[documentDirectory stringByAppendingPathComponent:[fileName copy]];
  
  NSString *mediaPathFinal=[NSString stringWithFormat:@"file://localhost%@",mediaPath];
  
  recordedTmpFile = [NSURL URLWithString:[mediaPathFinal stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&amp;error];
  
  recorder.delegate=self;
  
  
  [recorder recordForDuration:(NSTimeInterval) ([[appDelegate getTimeToRecord] intValue]+1)];
  
  }
  
  - (void) audioRecorderDidFinishRecording:(AVAudioRecorder *) recorder  successfully:(BOOL)flag
  {
  NSLog(@"DONE");
  }
  
  - (void) audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *) recorder error:(NSError *) error
  {
  NSLog(@"ERROR");
  }
  
  
  - (void) viewWillAppear:(BOOL)animated
  {
  
  
  AVAudioSession * audioSession = [AVAudioSession sharedInstance];
  [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &amp;error];
  
  [audioSession setActive:YES error: &amp;error];
  [audioSession setDelegate:self];
  
  [self record];
  [NSTimer scheduledTimerWithTimeInterval:([[appDelegate getTimeToRecord] intValue]+1) target:self selector:@selector(upload) userInfo:nil repeats:NO];
  
  
  }
  </code></pre>