Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIDocumentInteractionController和PDF_Ios_Uidocumentinteraction - Fatal编程技术网

Ios UIDocumentInteractionController和PDF

Ios UIDocumentInteractionController和PDF,ios,uidocumentinteraction,Ios,Uidocumentinteraction,我可以成功打开png文件,但当我尝试打开pdf时,预览显示“Portable Document Format”,而不显示内容 self.docInteractionController.UTI = @"com.adobe.pdf"; if ([operation isEqualToString:@"open"]) if (![self.docInteractionController presentPreviewAnimated:YES])

我可以成功打开png文件,但当我尝试打开pdf时,预览显示“Portable Document Format”,而不显示内容

    self.docInteractionController.UTI = @"com.adobe.pdf";

    if ([operation isEqualToString:@"open"])

        if (![self.docInteractionController presentPreviewAnimated:YES])
              NSLog(@"Failed to open document in Document Dir");

有什么提示吗?

对于其他来到这里的人。。。正如RyanJM所指出的,这似乎表明该文件实际上并没有按预期保存,也没有保存在URL显示的位置。另一种可能是您没有打开本地URL。虽然UIDocumentInteractionController可以获取URL,但它必须以文件开头://

您可以在本地下载,然后使用以下内容打开:

// Build URLS
NSURL* url = [[NSURL alloc] initWithString:@"http://MYURLGOESHERE"];
NSURL* documentsUrl = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject;
NSURL* destinationUrl = [documentsUrl URLByAppendingPathComponent:@"temp.pdf"];

// Actually download
NSError* err = nil;
NSData* fileData = [[NSData alloc] initWithContentsOfURL:url options:NSDataReadingUncached error:&err];
if (!err && fileData && fileData.length && [fileData writeToURL:destinationUrl atomically:true])
{
    // Downloaded and saved, now present the document controller (store variable, or risk garbage collection!)
    UIDocumentInteractionController* document = [UIDocumentInteractionController interactionControllerWithURL:destinationUrl];
    document.delegate = self;
    [document presentPreviewAnimated:YES];
}

你有没有想过?我只是在iOS8中遇到了这个问题。如果我记得很清楚,文件不在那里,因此没有什么可显示的。让我查一查密码……对不起,我本应该跟进的。我遇到的问题是没有正确保存文件。文件正确保存后,一切都正常了。