title: App crashes on click of Back button in iPhone
body: <p>I am new to iPhone,</p>
  
  <p>I am currently developing an iPhone app and in which i have implement the ability to download file from the url. I have created the UIWebView, when users clicks on download link in the <code>webview</code>, download will start and i am saving that file to a specified folder in the documents directory, this all things are working fine in my <code>Second View</code>..</p>
  
  <p>but after this when i press a back button for navigating to a my <code>First view</code>, my app gets crashed... shows <code>EXC_BAD_ACCESS</code></p>
  
  <pre><code>-(void)viewWillAppear:(BOOL)animated{
          //Doing some operation and it works fine...
             NSLog(@"viewWillAppear in First View.......");
      }
  
  -(void)viewDidAppear:(BOOL)animated{
      NSLog(@"viewDidAppear in First View.......");
  }
  </code></pre>
  
  <p>I am able to see above <code>Log</code> When i hit back button but my app crashes after 1 or half second.</p>
  
  <p>Here is my code in <code>Second View</code>,</p>
  
  <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  {
      [receivedData setLength:0];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data1
  {
      [receivedData appendData:data1];
  }
  
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
      NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
  
      DirPath=[self applicationDocumentsDirectory];
  
       NSLog(@"DirPath=%@",DirPath);
      [receivedData writeToFile:DirPath atomically:YES];
  
      UIAlertView* Alert = [[UIAlertView alloc] initWithTitle:@"Download Complete !"
                                                           message:nil delegate:nil 
                                                 cancelButtonTitle:@"OK"
                                                 otherButtonTitles:nil];
      [Alert show];
      [Alert release];
  
  
      // release the connection, and the data object
      [connection release];
      [receivedData release];
  }
  
  
  - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error1
  {
      [connection release];
      [receivedData release];
  
      // inform the user
      NSLog(@"Connection failed! Error - %@ %@",
            [error1 localizedDescription],
            [[error1 userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
  }
  
  - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
  
      url = [request URL];
  
      //CAPTURE USER LINK-CLICK.
  
              DirPath=[self applicationDocumentsDirectory];
  
              Durl=[[url absoluteString]copy];
  
              //Checking for Duplicate .FILE at downloaded path....
  
              BOOL success =[[NSFileManager defaultManager] fileExistsAtPath:path];
              lastPath=[[url lastPathComponent] copy];
  
              if (success) //if duplicate file found...
              {
                  UIAlertView* Alert = [[UIAlertView alloc] initWithTitle:@"This FILE is already present in Library."
                                                                       message:@"Do you want to Downlaod again ?" delegate:self 
                                                             cancelButtonTitle:nil
                                                             otherButtonTitles:@"Yes",@"No",nil];
                  [Alert show];
                  [Alert release];
  
              }
              else  //if duplicate file not found directly start download...
              {
                  // Create the request.
                  NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:Durl]
                                                            cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                        timeoutInterval:60.0];
  
                  // create the connection with the request and start loading the data
                  NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
                  if (theConnection) {
                      // Create the NSMutableData to hold the received data.
                      receivedData = [[NSMutableData data] retain];
                  } else {
                      NSLog(@"Inform the user that the connection failed."); 
                  }
  
      return YES;   
  }
  
  - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  { 
      if (buttonIndex == 0) 
      {        
          // Create the request.
          NSURLRequest *theRequest1=[NSURLRequest requestWithURL:[NSURL URLWithString:Durl]
                                                    cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                timeoutInterval:60.0];
  
          // create the connection with the request and start loading the data
          NSURLConnection *theConnection1=[[NSURLConnection alloc] initWithRequest:theRequest1 delegate:self];
          if (theConnection1) {
              // Create the NSMutableData to hold the received data.
              receivedData = [[NSMutableData data] retain];
          } else {
              NSLog(@"Inform the user that the connection failed."); 
          }
  
      }
      else
      {[alertView dismissWithClickedButtonIndex:1 animated:TRUE];}
  }
  
  - (void)webView:(UIWebView *)webview didFailLoadWithError:(NSError *)error1 {
  
      NSLog(@"didFailLoadWithError: %@; stillLoading:%@", error1,(webview.loading?@"NO":@"YES"));
  }
  </code></pre>
  
  <p>My Log shows: <code>didFailLoadWithError: Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo=0x6b34910 {NSErrorFailingURLKey=MY_URL, NSErrorFailingURLStringKey=MY_URL, NSLocalizedDescription=Frame load interrupted}; stillLoading:YES</code></p>
  
  <p><code>DirPath=/Users/krunal/Library/Application Support/iPhone Simulator/5.0/Applications/FCDDDE83-A9B3-4C14-A56C-E8C5FCE7F5C4/Documents/DownloadedFile.epub</code></p>
  
  <p><strong>Any help will be appriciated.</strong></p>