1. 程式人生 > >Open PDF Documents in iOS

Open PDF Documents in iOS

這個範例示範彈出 Open In 的選項,來開啟外部 App.

add <UIDocumentInteractionControllerDelegate>:

@interface ViewController : UIViewController <UIDocumentInteractionControllerDelegate>

Add a UIDocumentInteractionController property:

@property (nonatomic, strong) UIDocumentInteractionController *controller;

implement the openPDF IBAction method:

- (IBAction)openPDF:(id)sender 
{
 NSURL *URL = [[NSBundle mainBundle] URLForResource:@"MobileHIG" withExtension:@"pdf"];
 if (URL) 
 {
 self.controller = [UIDocumentInteractionController interactionControllerWithURL:URL]; 
 self.controller.delegate = self;

 // Present "Open In Menu"
 [self.controller presentOpenInMenuFromRect:[sender frame] inView:self.view animated:YES];
 } 
}

Done…