我正在制作一个应用程序,通过单击按钮下载 PDF 文件并通过应用程序的沙箱将其保存在本地。
现在,我想在下载过程中放置一个进度条,我该怎么做呢?
我已经设法使用此代码下载和查看文件...
存储数据:
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com/products/download/file.pdf"]];
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
filePath = [resourceDocPath stringByAppendingPathComponent:@"myPDF.pdf"];
[pdfData writeToFile:filePath atomically:YES];
文件查看:
UIWebView *pdfFileView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
pdfFileView.delegate = self;
pdfFileView.backgroundColor = [UIColor clearColor];
pdfFileView.opaque = NO;
pdfFileView.userInteractionEnabled = YES;
[self.view addSubview:pdfFileView];
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[pdfFileView loadRequest:requestObj];