Add actions to the browser's context menu.
Framework
- File
Provider UI
Overview
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
Add an NSExtension
key to the NSExtension
dictionary in your Info
file:
<key>NSExtensionFileProviderActions</key>
<array>
<dict>
<key>NSExtensionFileProviderActionIdentifier</key>
<string>com.example.MyFileProvider.setRating</string>
<key>NSExtensionFileProviderActionName</key>
<string>Rate</string>
</dict>
</array>
The NSExtension
key takes an array of dictionaries. Each dictionary represents a single action, and contains the keys shown in this table:
Key | Type | Description |
---|---|---|
|
| 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
FPUIAction
subclass.Extension View Controller The system calls your view controller's
prepare(for
method. 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.
After the user has finished performing the action, you call the provided
FPUIAction
object'sExtension Context cancel
orRequest(with Error:) complete
method to complete the action.Request()
Use Predicates to Enable and Disable Actions
The 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 use predicates to test the value of any of the NSFile
object's properties. For example, the following predicate tests whether the is
property is set to true
.
SUBQUERY ( fileproviderItems, $fileproviderItem, $fileproviderItem.uploadded == YES ).@count > 0
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.
SUBQUERY ( fileproviderItems, $fileproviderItem, $fileproviderItem.userInfo."com.example.testBit" == YES ).@count > 0
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.