2011-12-27 3 views
3

Я использую UIDocumentinteractioncontroller, чтобы открыть pdf-файл в другом приложении, таком как ibook.Как открыть pdf на другом приложении, например ibooks

Но трудно найти документ об этом.

Теперь я могу представить открытие частично. но когда я нажимаю на значок ibooks. ничего не случилось.

Нужно ли что-то делать в делегате, таком как documentInteractionController: willBeginSendingToApplication: ???

+0

Ответ есть в следующем посте http://stackoverflow.com/questions/6741565/docinteraction-sample-code-uidocumentinteractioncontroller-broken-on-ios-4 -3-е – ArunaFromLK

ответ

0

сначала нужно добавить UIDocumentInteractionControllerDelegate в вашем файле .h

т.е.:

@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; 
}