【问题标题】:how to open pdf on other application like ibooks如何在 ibooks 等其他应用程序上打开 pdf
【发布时间】:2011-12-27 10:39:03
【问题描述】:

我使用 UIDocumentinteractioncontroller 在 ibook 等其他应用上打开 pdf。

但是很难找到关于它的文档。

现在我可以展示部分公开内容了。但是当我点击 ibooks 的图标时。什么都没发生。

我是否需要在委托中做一些事情,例如 documentInteractionController:willBeginSendingToApplication:???

【问题讨论】:

标签: objective-c


【解决方案1】:

首先你必须在你的 .h 文件中添加 UIDocumentInteractionControllerDelegate

即:

@interface MyDocumentViewController : UIViewController <UIDocumentInteractionControllerDelegate> 

在您的 .m 文件中添加协议,这使您能够了解发生了什么...

- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application{
    NSLog(@"Send to App %@  ...", application);   
}

- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application{
    NSLog(@"Finished sending to app %@  ...", application);   

}

- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller{
    NSLog(@"Bye");   

}

当然,您必须将 UIDocumentInteractionController 的委托设置为该模块。我是这样解决的:

-(BOOL)canOpenDocumentWithURL:(NSURL*)url inView:(UIView*)view {
    BOOL canOpen = NO;
    UIDocumentInteractionController* tmpDocController = [UIDocumentInteractionController 
                                                      interactionControllerWithURL:url];
    if (tmpDocController)
    {
        tmpDocController.delegate = self;
        canOpen = [tmpDocController presentOpenInMenuFromRect:CGRectZero
                                                    inView:self.view animated:NO];                   
        [tmpDocController dismissMenuAnimated:NO];
    }
    return canOpen;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多