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

  • Home
  • SEARCH
  • 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 890831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:47:45+00:00 2026-05-15T13:47:45+00:00

Me again! I am using NSURL to get a file then parse it. I

  • 0

Me again! I am using NSURL to get a file then parse it. I have been looking for a couple of hours now on a progressbar i am trying to implement in my app. I know I first need to get the file size, then keep updating how much data i’ve downloaded as I continue to pull. I have seen the example using “ASIHTTPRequest” but is there a way to do it with what I already have?

Here is where I start the download.

-(void)parseNewData {


    //start network activity spinner and release controller when done
    parserDone = NO;
    [root downloadIcon];


    //create pool to avoid memory leak
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];


    // get the XML path and start parsing
    NSURL *pathURL = [NSURL URLWithString:@"http://www.mysite.com/myfile.xml"];




    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
    [parser setDelegate:self];
    [parser parse];

    //drain pool 
    [pool drain];
    [pool release];

}

Can someone point me in the right direction on how to get file size, then how to update how much I’ve downloaded. Thanks in advance!

  • 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-05-15T13:47:46+00:00Added an answer on May 15, 2026 at 1:47 pm

    You need to use NSURLConnection if you want to get the file size and the progress. You get delegate methods which you can use to monitor progress. The didSendBodyData: delegate method tells you how much data there is in bytes. The connectionDidFinishLoading is where you uget receivedData to use in your NSXMLParser code.

    NSURLRequest *theRequest = [NSURLRequest requestWithURL:URL    cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (theConnection) {
    
        receivedData = [[NSMutableData data] retain];
    }
    
    }
      - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    // This method is called when the server has determined that it
    // has enough information to create the NSURLResponse.
    
    // It can be called multiple times, for example in the case of a
    // redirect, so each time we reset the data.
    
    // receivedData is an instance variable declared elsewhere.
    [receivedData setLength:0];
    }
     - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    // release the connection, and the data object
    
    // inform the user
    NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
    [connection release];
    // receivedData is declared as a method instance elsewhere
    [receivedData release];
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    // Append the new data to receivedData.
    // receivedData is an instance variable declared elsewhere.
    [receivedData appendData:data];
    }
    - (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to get OAuth for Twitter to work on my iPhone application
Alright I have two problems. I'm using AVAudioPlayer to play a simple audio file
using some of the nifty new APIs in iOS4 i am trying to capture
I have to show rich text that i pull from server, so i'm using
I load a page, saw on twitter, using a line like this: [self.webView loadRequest:[NSURLRequest
I was previously downloading images for my app by using dataWithContentsOfURL to download a
I have a small iPhone app which has a button on the first view.
I have a little app that downloads stock prices and was working perfectly (for
I'm tinkering with adding a model layer to an iPhone application so that 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.