【问题标题】:How to view the downloaded files in Device ipad/iphone如何在设备 ipad/iphone 中查看下载的文件
【发布时间】:2014-07-20 04:02:06
【问题描述】:

嗨,在我的应用程序中,我可以选择下载我搜索过的 pdf 文件,我得到了在我的 mac 中使用它的代码,我可以看到下载的 pdf 文件。但问题是,如果我在设备中下载相同的 pdf,我可以在设备中找到下载的 pdf 文件。

这是我用来下载 pdf 文件的代码。

 NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://jesusredeems.com/mag/pdf/JRE-2014-03.pdf"]]; //Store the Data locally as PDF File
 NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];

 NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"11011.pdf"]; [pdfData writeToFile:filePath atomically:YES]; NSLog(@"%@",filePath);

如果我打印文件路径,我会得到这样的结果。

/var/mobile/Applications/353C27AD-1E64-41CA-A429-16C2A20C8606/Documents/11011.pdf

在我的 Mac 中,我可以在该路径中看到下载的文件,但在我的 Ipad 中,我可以看到下载的 pdf 文件,请任何人告诉我必须在哪里找到它。

谢谢。

【问题讨论】:

    标签: ios ipad pdf download


    【解决方案1】:

    您的保存部分很可能是正确的,但还是试试吧。

    NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://jesusredeems.com/mag/pdf/JRE-2014-03.pdf"]]; 
    
     NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
            NSString* documentsPath = [paths objectAtIndex:0];
            NSString *destPath = [documentsPath stringByAppendingPathComponent:@"11011.pdf"];
    
     [pdfData writeToFile:destPath atomically:YES]; 
    

    然后执行此操作来检索它。

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
        NSString* documentsPath = [paths objectAtIndex:0];
        NSString* dataFile = [documentsPath stringByAppendingPathComponent:@"11011.pdf"];
        NSData *pdfData3 = [NSData dataWithContentsOfFile:dataFile];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      相关资源
      最近更新 更多