Add actions to the browser's context menu.
Define custom actions in your File Provider UI extension's
Info file. These actions appear in the context menu when the user long presses an item while browsing your file provider's content.
Add Actions to the Context Menu
NSExtension key to the
NSExtension dictionary in your
NSExtension key takes an array of dictionaries. Each dictionary represents a single action, and contains the keys shown in this table:
A unique identifier for the action.
The localized name that appears in the context menu.
An optional predicate that determines whether the action appears in the context menu.
The following sequence of events occurs when the user selects one of your actions from the context menu:
The system instantiates your
Extension View Controller
The system calls your view controller's
prepare(formethod. You can override this method to configure the user interface for the selected action.
Action: item Identifiers:)
The system presents your view controller to the user.
Use Predicates to Enable and Disable Actions
NSExtension key lets you enable or disable actions based on the selected file provider item. Set the key's value to a predicate format string. The system uses this string to create an
NSPredicate object, and then calls the predicate's
evaluate(with:) method, passing in the selected item. Specifically, it passes in a dictionary with a single
fileprovider key. The value is an array of
NSFile objects representing the selected items.
You can also use predicates to test custom data that you've added to the item's
user dictionary. For example, the following predicate tests whether the
com key has been set.
If a predicate evaluates to
true, the action is displayed; if
false, it's not displayed. For more about creating predicate format strings, see Predicate Format String Syntax.