ボタンをクリックして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];