【问题标题】:How to save and fetch multiple pdf files in NSDocument Directory in Objective-C?如何在 Objective-C 的 NSDocument 目录中保存和获取多个 pdf 文件?
【发布时间】:2020-04-01 11:54:00
【问题描述】:

我正在从服务器下载多个 pdf 文件。下载完成后,我需要将 pdf 文件保存在本地并从 pdf 文件中获取并在 UIDocument 交互控制器中显示 pdf 文件。我是这样写的。但只显示一个文件。其余文件不显示。

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [self.data appendData:data];

    NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];        // get 
    /tmp folder path

    NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"temp_pdf"] URLByAppendingPathExtension:@"pdf"];

    [self.data writeToURL:fileURL atomically:YES];

    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];

    self.documentInteractionController.delegate = self;

    [self.documentInteractionController presentPreviewAnimated:YES];
}

【问题讨论】:

    标签: ios objective-c iphone xcode


    【解决方案1】:

    NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filePath = [documents stringByAppendingPathComponent:@"file.plist"];

    【讨论】:

    • .plist 文件我们无法保存。为什么,因为我们有很多来自服务器的 pdf 文件。
    • 我有很多 pdf 文件,我需要在本地保存多个 pdf 文件。并获取多个 pdf 文件。
    猜你喜欢
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 2013-01-07
    相关资源
    最近更新 更多