UIDocumentBrowserViewController.customActions can't be filtered on a per-file basis

Number:rdar://45710119 Date Originated:31-Oct-2018 02:30 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:12.1
Classification:Enhancement Reproducible:Always
UIDocumentBrowserViewController lets the user add custom actions that are executed on selected items in the file browser. However, these actions are provided just once and are expected to work for all the items being presented in the view controller. 

I see how there could be an expectation that all the custom actions should be able to work with all the items in the file browser based on the file types that the browser can display. However, this is not always true. 

A concrete example would be that our application, PDF Viewer, displays PDF files, but a PDF file has internal flags that control a bunch of features — printing, sharing, and editing, to name a few. A user can tap and hold a PDF on the file browser to reveal a list of actions to execute on that file. 

At this point, it would be useful for us to be able to filter out the custom actions that don’t make sense in the context of the item that’s selected. Say, if the document (which we already have on disk and can parse to get its features) can’t be printed based on permissions, then we could hide the Print action from that menu.

Although we can easily work around this API limitation by adding a bunch of checks in our custom sharing UI to see if the document is locked or not and then offer the user the option to unlock it, I think it could be really useful to offer this via a delegate call so that the UI/UX could be tailored more efficiently depending on the file that’s given as a context for the custom action.

Steps to Reproduce:
1. Implement a custom UIDocumentBrowserViewController subclass and instantiate it with a desired type identifier.
2. Add a set of UIDocumentBrowserAction with availability set to .menu to the view controller’s .customActions property.
3. Run the app, tap and hold on an item on the file browser to reveal the action menu.
4. Notice how all the actions are available for every item, and there’s no way to filter out those actions that don’t make sense for the current item being selected.

Expected Results:
There is a way to filter out custom actions from the UIMenuController that are not relevant for the current item that’s showing that menu. Ideally through a delegate callback or an NSPredicate that can be defined on the UIDocumentBrowserAction at instantiation time.

Actual Results:
There is not a way to filter out custom actions from the UIMenuController that are not relevant for the current item that’s showing that menu.




Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!