I have an extension in my app that allows users to pick pictures or video of their 'Photos/Pictures' app to publish in my app.
I limit the number of pictures to 20 and the limit of videos to 1 by doing the following :
However, I want my users to select multiple pictures or only one video, which is not possible with this configuration.
I have read this post: NSExtension Share Extension limit Photos count
They explain that I can do a custom validation rule but I have no idea how to write it. Is there any other Activation parameter or can someone help with writing the rule?
Thanks in advance!
Apple offers an option to do things like you want. We can take a look at the docs here:
https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW8
I modified the UTI-CONFORMS-TO
items to video and images, and the counts a bit:
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
).@count <= 20
).@count >= 1
OR
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY(
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.video"
).@count == 1
).@count == 1
This query should limit the selection to only 1 video or 1 to 20 images. Note that you should specify this query like the following:
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>
--- SUBQUERY HERE ---
</string>
</dict>
I did not test this code and it might not fully work, but it will point you in the right direction.
Here's a valid answer, oddly I didn't manage to make logical conditions (AND / OR) work in a single subquery so I had to split it :
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY(
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
).@count == 1
AND
SUBQUERY(
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
).@count == 0
).@count == 1
OR
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY(
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
).@count == 0
AND
SUBQUERY(
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
).@count <= 20
).@count >= 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With