title: Save the The Stream From URL
body: <p>In my project I am connecting a url and I am watching a video  with MPMoviePlayerViewController. But that is not enough to me. I also want to save the file to my Iphone. I have to buttons. one is watch the video, the other is save the video. When I push the button watch I am watchng it. But unable to save it. by this I want to be able to watch the video later. So in another view I want to see saved videos etc. Is there any one can help me or can show the way ?  I have tried following code phrase but When the code started, It works for a while (probably it is the download time), but when it is time to save I get Bad EXC_BAD_ACCESS error .Thanks every one.<br>
  Here is my code . </p>
  
  <pre><code>CFStringRef *docsDirectory =  (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.mp4"];
  
  
  NSString *temPath=NSTemporaryDirectory();
  NSString *tempfile=[temPath stringByAppendingPathComponent:@"recode.mp4"];
  
  
  NSLog(@" DOSYA ADI MADI %@",docsDirectory);
  
  
  NSFileManager *fileManager = [NSFileManager defaultManager];
  NSError *error = [[NSError alloc] init];
  
  [fileManager removeItemAtPath:docsDirectory error:&amp;error];
  
  NSURL *url = [NSURL URLWithString:@"http://video.teknomart.com.tr/3-13-2.mp4"];
  
  NSMutableURLRequest *liveRequest = [[NSMutableURLRequest alloc] initWithURL:url];
  [liveRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
  
  [liveRequest setValue:@"headervalue" forHTTPHeaderField:@"headerfield"];
  
  NSURLResponse *response;
  NSData *myData = [NSURLConnection sendSynchronousRequest:liveRequest returningResponse:&amp;response error:&amp;error];
  NSData *myData2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://video.teknomart.com.tr/3-13-2.mp4"]];
  
  NSString *myString=[[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
  
  NSLog(@"gelen sey %@",myString);
  
  [myString writeToFile:tempfile writeToFile:tempfile automatically:YES encoding:NSASCIIStringEncoding error:nil];
  
   [myString release];
  return true;
  </code></pre>