UIDocumentsInteractionController shows iBooks but doesn't open it

给你一囗甜甜゛ 提交于 2019-12-07 10:27:46

问题


My UIDocumentsInteractionController is working as far as presenting an action sheet with a button that says "iBooks" but when I click on that button, it just dismisses and it doesn't take me to iBooks. Here's my code:

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

What am I doing wrong? Thanks


回答1:


For those stuck at this: You don't need to set yourself up as UIDocumentInteractionController's delegate at all.

Problem was [UIDocumentInteractionController interactionControllerWithURL:url] is being autoreleased. It thought it would be retained internally by the action sheet being shown but apparently it's not. So yea, gotta retain it until action sheet dismisses.




回答2:


Try checking the UIDocumentInteractionControllerDelegate methods documentInteractionController:willBeginSendingToApplication: and documentInteractionController:didEndSendingToApplication:. If your view controller is the delegate of the document interaction controller, that should clue you in to where the problem may be.

Also, you should validate that the file you're trying to use elsewhere (a PDF I assume) is actually a what you expect it to be.



来源:https://stackoverflow.com/questions/9792228/uidocumentsinteractioncontroller-shows-ibooks-but-doesnt-open-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!