I am using following code for downloading epub /pdf from a url .I like to give a progress bar so when I start downloading it shows the progress and when the download completes it will popup a message. How can I implement this?
My code for downloading file
-(void)Download
{
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.feedbooks.com/book/3471.epub"]];
//Store the Data locally as epub File if u want pdf change the file extension
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"3471.epub"];
[pdfData writeToFile:filePath atomically:YES];
NSLog(@"%@",filePath);
}
I am using this codes in my .m file but it's not working for me
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
_totalFileSize = response.expectedContentLength;
responseData = [[NSMutableData alloc] init];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
_receivedDataBytes += [data length];
MyProgressBar.progress = _receivedDataBytes / (float)_totalFileSize;
[responseData appendData:data];
}