Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:18:35+00:00 2026-06-10T11:18:35+00:00

I am new to iPhone, I am currently developing an iPhone app and in

  • 0

I am new to iPhone,

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 webview, 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 Second View..

but after this when i press a back button for navigating to a my First view, my app gets crashed… shows EXC_BAD_ACCESS

-(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.......");
}

I am able to see above Log When i hit back button but my app crashes after 1 or half second.

Here is my code in Second View,

- (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"));
}

My Log shows: didFailLoadWithError: Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo=0x6b34910 {NSErrorFailingURLKey=MY_URL, NSErrorFailingURLStringKey=MY_URL, NSLocalizedDescription=Frame load interrupted}; stillLoading:YES

DirPath=/Users/krunal/Library/Application Support/iPhone Simulator/5.0/Applications/FCDDDE83-A9B3-4C14-A56C-E8C5FCE7F5C4/Documents/DownloadedFile.epub

Any help will be appriciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:18:36+00:00Added an answer on June 10, 2026 at 11:18 am

    I think your are releasing wrong things… Consider this,

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error1
    

    no need to release connection, receivedData

    at dealloc block, add this code

    - (void) dealloc
      {
          if (theConnection)
          { 
               [theConnection release], theConnection = nil;
          }
    
          if (receivedData)
          { 
               [receivedData release], receivedData = nil;
          }
      }
    

    add if you are using same webView to create multiple connection, then add

    if (theConnection)
    { 
          [theConnection release], theConnection = nil;
    }
    
    if (receivedData)
    { 
         receivedData release], receivedData = nil;
    }
    

    before allocating URLConnection and NsMutableData, thats a measure to stop memory leaks. And better to have a activity spinner until event is done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to iphone development. I am currently doing a restaurant app which
I am currently developing an iPhone application which loads data from an RSS feed
I am new to iPhone, I am currently developing an iPhone app and would
I'm currently working on a concept for a new iPhone app, the would involve
I’m writing a new iPhone app which doesn’t depend on any of the 3.0
I have a new iPhone app that has the following (and only the following)
I am developing an iPhone application which logs data in a mySql database. Currently
I am new to iPhone development.Currently I am working on an application in which
I am very new to iOS development. I am developing an app, currently i
I am currently writing my first iPhone app, but have encountered an issue. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.