gpt4 book ai didi

ios - UIDocumentInteractionController和PDF

转载 作者:行者123 更新时间:2023-12-01 18:59:21 25 4
gpt4 key购买 nike

我可以成功打开png文件,但是当我尝试打开pdf时,预览显示“便携式文档格式”而不显示内容。

    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,但必须以file://开头

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

// 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];
}

关于ios - UIDocumentInteractionController和PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23874220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com