UIDocumentsInteractionController显示iBooks但不打开它

0xS*_*ina 4 iphone cocoa-touch objective-c ios uidocumentinteraction

我的UIDocumentsInteractionController正在使用一个带有"iBooks"按钮的动作表,但是当我点击那个按钮时,它只是解散它并没有把我带到iBooks.这是我的代码:

NSString *filenamePath =[NSString stringWithFormat:@"temp.%@", [[file path] pathExtension]];

    NSString *docDir = [DataCenter getDocumentsDirectoryPath];

    NSString *fullPath = [docDir stringByAppendingPathComponent:filenamePath];

    NSURL *url = [NSURL fileURLWithPath:fullPath];
    UIDocumentInteractionController *c = [UIDocumentInteractionController interactionControllerWithURL:url];

    BOOL success = [c presentOpenInMenuFromBarButtonItem:buttonBack animated:YES];
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?谢谢

0xS*_*ina 18

对于那些坚持这一点的人:你根本不需要将自己设置为UIDocumentInteractionController的委托.

问题[UIDocumentInteractionController interactionControllerWithURL:url]是正在自动释放.它认为它会被显示的动作表内部保留,但显然不是.所以,是的,必须保留它,直到行动表解散.

  • 哇 - 好吧,即使是ARC也是如此!你需要创建一个名为`self.interactionController`(或类似)的属性和alloc-init,或者它被释放.谢谢@PragmaOnce! (5认同)