-2

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

1 に答える 1

0

プログレスバーでダウンロードするには、このデモを試してください

NPR画像ビュー

2 つのフォルダー ファイルをダウンロードすると、見つからない可能性があり、エラーが発生します。このトウフォルダーフォームをここからダウンロードしてください

https://github.com/nicnocquee/NPRImageView/

于 2013-05-08T05:18:59.673 に答える