Reputation: 12859
I am building an app with an action extension. For that, the extension should enable only if the user selects either one video or one image(it can process one file/object at once). I got the NSExtensionActivationRule
predicate from apple documentation
Like this,
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.action-one" ||
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.action-two"
).@count == $extensionItem.attachments.@count
).@count == 1
And the documentation says
This statement iterates over an array of NSExtensionItem objects, and secondarily over the attachments array in each extension item. For each attachment, the predicate evaluates the uniform type identifier (UTI) for each representation in the attachment. When an attachment representation UTI conforms to any of of two different specified UTIs (which you see on the right-hand side of each UTI-CONFORMS-TO operator), collect that UTI for the final comparison test. The final line returns TRUE if the app extension was given exactly one extension item attachment with a supported UTI.
I changed org.appextension.action-two
and org.appextension.action-one
to public.image
and public.movie
.
But still the extension is enabled even if I select multiple video or images. What is wrong with the predicate.
Upvotes: 1
Views: 1017
Reputation: 31
The condition @count == $extensionItem.attachments.@count
means it will return true if all the attachments are images and videos and it doesn't matter how many are there, to limit it to only 1 change this to @count == 1
Upvotes: 1