如何在ibooks等其他应用程序上打开pdf

时间:2011-12-27 10:39:03

标签: objective-c

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

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

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

我是否需要在委托中执行某些操作,例如documentInteractionController:willBeginSendingToApplication:???

1 个答案:

答案 0 :(得分:0)

首先你必须在你的.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;
}