Open in + UIDocumentInteractionController : how to filter options in SDK iOS 6 (canPerformActions is deprecated)
Asked Answered
H

2

16

Since the new SDK was release (iOS 6), the delegate method documentInteractionController:canPerformAction: of the UIDocumentInteractionControllerDelegate is deprecated.

Using that method you were able to prevent default actions like print: and copy: to appear.

The method is being called in the current version of iOS 6, but in future versions this method will not be called and my app will show actions that I don't want to support.

I read the available documentation for the UIDocumentInteractionController and its delegate and I'm not able to find a another way to do what I do in the canPerformAction method.

Any ideas?

As a plus, it would be great to be able to filter apps like mail or twitter (that appears by default) but I guess that this is not possible.

Hermaphroditus answered 25/9, 2012 at 22:13 Comment(0)
T
6

I think it is because Apple wants you to use the new UIActivity control.

Here it's the documentation:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html

Here it's a custom control developed to support many third party apps:

http://www.cocoacontrols.com/platforms/ios/controls/uiactivitycollection

And this question solves how could you make your own UIActivity:

https://mcmap.net/q/299808/-how-can-i-create-a-custom-uiactivity-in-ios

So, if you don't want the user can use copy: and print: methods just pass this activities to the UIActivityViewController, like this:

[activityView setExcludedActivityTypes:[NSArray arrayWithObjects:UIActivityTypeCopyToPasteboard, UIActivityTypePrint, nil]];

All the default activities are listed at the bottom of the Apple's documentation link.

Talipes answered 20/12, 2012 at 15:17 Comment(3)
Hey.. thanks for the answer! I didn't see that coming jaja I will dig into this, but at a glance it seems to be the future. Thanks again!Hermaphroditus
so... if this were true, how would you open a file in another application (currently working with UIDocumentInteractionController's openWith… and QuickLookPreview?). AFAICS there's no support for this in UIActivityViewController (besides that UIActivityViewController has some quite severe limitations as well)Sheeting
Agree with auco - how can you now open in... xlxs or similar with iOS6?Magness
W
8

Agreed on the fact that deprecating 'canPerformAction' in the delegate is troublesome, we lost the fine grain control we used to have.

However, if all you want is to allow a document to be opened in another app, and wanted to remove Copy, Print and even Mail, I guess you are better off using OpenIn version of method to present the UIDocumentInteractionController?

i.e. for your UIDocumentInteractionController use presentOpenInMenuFromBarButtonItem:animated: or presentOpenInMenuFromRect:inView:animated:

(instead of presentOptionsMenuFromBarButtonItem:animated: or presentOptionsMenuFromRect:inView:animated:)

This way, by default, it will only show apps that can open your document, and hides Mail, Copy and Print.

Weber answered 8/3, 2013 at 3:4 Comment(3)
This way makes rest of options unavailable too (FB, Twitter etc). What if someone wants to have OpenIn and FB..?Auric
On the simulator there may be no installed apps to open the content and the menu will not show. See this Q&A: #23624718Canaletto
It doesn't make the other options unavailable btw. And it's currently the only way to Share to Instagram, for example. The sad state of iOS inter-app sharing/communications.Oneidaoneil
T
6

I think it is because Apple wants you to use the new UIActivity control.

Here it's the documentation:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html

Here it's a custom control developed to support many third party apps:

http://www.cocoacontrols.com/platforms/ios/controls/uiactivitycollection

And this question solves how could you make your own UIActivity:

https://mcmap.net/q/299808/-how-can-i-create-a-custom-uiactivity-in-ios

So, if you don't want the user can use copy: and print: methods just pass this activities to the UIActivityViewController, like this:

[activityView setExcludedActivityTypes:[NSArray arrayWithObjects:UIActivityTypeCopyToPasteboard, UIActivityTypePrint, nil]];

All the default activities are listed at the bottom of the Apple's documentation link.

Talipes answered 20/12, 2012 at 15:17 Comment(3)
Hey.. thanks for the answer! I didn't see that coming jaja I will dig into this, but at a glance it seems to be the future. Thanks again!Hermaphroditus
so... if this were true, how would you open a file in another application (currently working with UIDocumentInteractionController's openWith… and QuickLookPreview?). AFAICS there's no support for this in UIActivityViewController (besides that UIActivityViewController has some quite severe limitations as well)Sheeting
Agree with auco - how can you now open in... xlxs or similar with iOS6?Magness

© 2022 - 2024 — McMap. All rights reserved.