Я использую следующий код для загрузки epub / pdf с URL-адреса. Мне нравится показывать индикатор выполнения, поэтому, когда я начинаю загрузку, он показывает прогресс, а когда загрузка завершается, появляется всплывающее сообщение. Как я могу реализовать это?
Мой код для загрузки файла
-(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);
}
Я использую эти коды в своем файле .m, но у меня это не работает.
-(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];
}