UIDocumentInteractionController adding custom actions to menu (eg email, save to photos)
You are correct, These are the methods
- (BOOL) documentInteractionController: (UIDocumentInteractionController *) controller performAction: (SEL) action- (BOOL) documentInteractionController: (UIDocumentInteractionController *) controller canPerformAction: (SEL) action
The supported action selectors for these methods are copy: and print:.
I cannot comment yet so I'm answering instead :-)
You should give QuickLook framework a try. In my case, I searched all over how to customize UIDocumentInteractionController and failed to find anything useful. I achieved what I wanted (in my case, having a preview "view" inside another view) using QuickLook. Here's a sample code, to have a QLPreviewController as a child controller (being able to create the parent controller freely, which will do the trick in your case).
self.previewController = [[QLPreviewController alloc]init];self.previewController.delegate=self;self.previewController.dataSource=self;[self addChildViewController:self.previewController];self.previewController.view.frame = CGRectMake(0, 0, self.previewView.frame.size.width, self.previewView.frame.size.height);[self.previewView addSubview:self.previewController.view];[self.previewController didMoveToParentViewController:self];
You will also need some delegates: QLPreviewControllerDataSource and QLPreviewControllerDelegate
and also some need to implement:
- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
return NSURL to the resource
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
return the number of items to preview (in my case, 1)
To display email and 'save to' options you should use
- (BOOL)presentOptionsMenuFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;
or
- (BOOL)presentOptionsMenuFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;
As described in UIDocumentInteractionController.h :
/ This is the default method you should call to give your users the option to quick look, open, or copy the document. /
While using
// Presents a menu allowing the user to open the document in another application.
- (BOOL)presentOpenInMenuFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated;
or
- (BOOL)presentOpenInMenuFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;
email, sms and 'save in photo/video' are not displayed.
If other actions are required that are not recognized, consider using UIActionSheet.