This question already has an answer here:
I am trying to put a progress bar that syncs during the download that is happening. My app now can download a file using with this codes...
pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://webaddress.com/pro/download/file.pdf"]];
NSString *resourcePDFPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
pdfFilePath = [resourcePDFPath stringByAppendingPathComponent:@"myPDF.pdf"];
[pdfData writeToFile:pdfFilePath atomically:YES];
During the process of this code the app stopped during download, is it normal? Now what I want is to put a progress bar during that stop time while downloading.
I tried looking into the codes I found online but I'm a bit confused, I think I need a step-by-step-well-explained reference.
First of all you should be clear whether to make a synchronous call or asynchronous. For mobile apps or any other app asynchronous is preferred one.
Once you are clear use NSURLConnection class to fetch the data from the URL. Here is the good tutorial.
And for loading you can start progress while starting the request and stop it when you receive
connection:didFailWithError:
orconnectionDidFinishLoading:
delegate method.I'm afraid it's not normal, use asynchronous method to get the NSData.
Use ASIHTTPRequest.h class and ASINetworkQueue.h for downloading the file.
and use this code for progress bar
this may help you
Using AFNetworking,
here progress is the UIProgressview
Using NSURLConnection