Open PDF Documents in iOS

Posted in :

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

sample:
https://www.ioscreator.com/tutorials/open-pdf-documents-in-ios


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…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *