Ios UIDocumentInteractionController和PDF
我可以成功打开png文件,但当我尝试打开pdf时,预览显示“Portable Document Format”,而不显示内容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])
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中遇到了这个问题。如果我记得很清楚,文件不在那里,因此没有什么可显示的。让我查一查密码……对不起,我本应该跟进的。我遇到的问题是没有正确保存文件。文件正确保存后,一切都正常了。