【问题标题】:UIDocumentInteractionController will fail to open document in IbookUIDocumentInteractionController 将无法在 Ibook 中打开文档
【发布时间】:2012-07-02 11:55:09
【问题描述】:

问题是“成功”总是返回错误?我不知道是什么问题?

我的代码如下:

UIDocumentInteractionController *docController = [[UIDocumentInteractionController interactionControllerWithURL:currentPDFPath] retain];

if (docController)
{
    docController.delegate = self;

    BOOL success = [docController presentOptionsMenuFromBarButtonItem:openInButton animated:YES]; 
    //BOOL success = [docController presentOpenInMenuFromBarButtonItem:openInButton animated:YES];
    NSLog(@"success: %d", success);
    if(!success)
    {
        UIAlertView * noApps = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your iPad doesn't seem to have any other Apps installed that can open this document (such as iBooks)" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [noApps show];
        [noApps release];

    }
}
    [docController release];

【问题讨论】:

  • currentPDFPath 包含什么?
  • file://localhost/var/mobile/Applications/14DD059B-9969-4960-8E24-DC586A4302D1/Library/Caches/http-_wgsn.howoco.com_media_event_117_AW12_13_Tradeshow_seasonal_analysis-_colour_1340296472 .pdf%3F1340297029
  • @PriyankaChhetri 你找到解决方案了吗,请告诉我,谢谢:)

标签: objective-c ios ipad ibooks uidocumentinteraction


【解决方案1】:

class reference documentation 说:

返回值

YES 如果选项菜单已显示,NO 如果未显示。如果菜单中没有合适的项目,则可能不会显示选项菜单。

我认为currentPDFPath 上的%3F1340297029 后缀可能会阻止UTI 匹配。

检查docControllerUTI属性,如果是nil则设置为kUTTypePDF

【讨论】:

  • 感谢您的回复。我的这个问题已经解决了。现在“BOOL 成功”返回 1。但我无法在 iBook 中打开此 pdf。
  • 现在的错误是“*** Terminating app due to unaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc]达到了同时popover仍然可见。”
【解决方案2】:

您的崩溃问题可能是因为您的 docController 已经发布。您需要保留它,然后稍后自动释放它。看看这里:

https://stackoverflow.com/a/3474825/523350

【讨论】:

    【解决方案3】:

    我稍微修改了你的代码,但它不适合我,我使用的是 ARC,所以你必须更改它以适应你的非 ARC 代码。

    BOOL success = [self.documentInteractionController presentOpenInMenuFromRect:rect inView:self.view animated:YES];
    
                    if (success == NO) {
                        NSLog(@"No application was found");
                    } else {
    
                        NSLog(@"Applications were found");
                    }
    

    BOOL 要么返回YESNOYES 它后面的行=TRUENO,如果行是FALSE

    --大卫

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 2016-03-17
      • 1970-01-01
      • 2015-04-06
      • 2013-09-28
      相关资源
      最近更新 更多