Objective-C下载文件并将其与Document Interaction Controller一起使用

时间:2015-09-15 14:18:01

标签: ios objective-c

我这里有这个代码,这是不完整的。第一部分从URL下载文件:

NSString *stringURL = @"http://www.example.com/pdf/035.pdf";
        NSURL  *url = [NSURL URLWithString:stringURL];
        NSData *urlData = [NSData dataWithContentsOfURL:url];
        if ( urlData )
        {
            NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString  *documentsDirectory = [paths objectAtIndex:0];

            NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"035.pdf"];
            [urlData writeToFile:filePath atomically:YES];
        }

并将其放入:var / mobile / Containers / Data / Application /

现在我想将此下载文件与Document Interaction Controller一起使用,如下所示:

NSURL *URL = [[NSBundle mainBundle] URLForResource:@"035" withExtension:@"pdf"];

if (URL) {
    // Initialize Document Interaction Controller
    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];

    // Configure Document Interaction Controller
    [self.documentInteractionController setDelegate:self];

    // Preview PDF
    [self.documentInteractionController presentPreviewAnimated:YES];
}

我如何从var / mobile / Containers / Data / Application /获取文件并使用Document Interaction Controller显示它?

0 个答案:

没有答案