目标C:下载时的进度条

时间:2013-05-08 04:13:26

标签: ios objective-c nsdata

我正在创建一个应用程序,按下按钮下载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];

1 个答案:

答案 0 :(得分:0)

尝试使用进度条下载此演示

NPRImageview

当您下载两个文件夹文件时可能会丢失并给您一个错误。从这里下载这个两个文件夹表格

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