UIDocumentInteractionController adding custom actions to menu (eg email, save to photos)
Asked Answered
J

4

26

I've started using UIDocumentInteractionController for a new app but I'm wondering how to add additional actions to the action menu that you get on the preview screen?

It seems that the menu only lists apps that have registered for a given url type plus I'm seeing PRINT showing up on iOS4.2. I would like to add send by email and save to photos but don't see a way of extending this menu. I can code the actions I want OK, it's just adding them into the menu that seems impossible?

Am I missing something obvious?

Jeep answered 5/3, 2011 at 15:56 Comment(5)
Why don't you think different approach, UIActionSheet contains: Email this.. , Open with.., Open with Phone Galary.., why you insist to include all these in the menu of UIDocumentInteractionController?Insightful
@AhmadTK, he could be working on an iPad as well?Peden
@phooze: 1st: he did not mentioned that 2nd: I made the suggested approach and it's working like a charm in ipad too'.Insightful
To clarify, yes, this is (was) an issue with the iPad version of a universal app. The issue is with user flow, it is natural to view a document and then do something with it. It's a shame that it seems not to be possible to extend the action menu that offers print and open with since this is the logical place to add some additional features such as email.Jeep
@AhmadKayyali Taking open with words as an example, how do you implement that by yourself if we use UISheetAction instead of UIDocumentInteractionController?Ovoviviparous
I
2

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:.

Inalterable answered 3/5, 2011 at 13:34 Comment(1)
These functions are deprecated as of iOS 6.0.Photoelectrotype
S
2

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)

Sammy answered 27/1, 2014 at 15:7 Comment(0)
G
2

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.

Granicus answered 18/11, 2014 at 8:16 Comment(0)
S
0

i could suggest a simple UIActionSheet or better a popover if you are on iPad with inside a table view with apps and you can manually add Print,email and everything else.

Sippet answered 15/10, 2011 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.