Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSExtension - Share - Limit type only to video or only to pictures

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 : enter image description here

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!

like image 982
Melanie Journe Avatar asked Nov 29 '18 16:11

Melanie Journe


2 Answers

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.

like image 193
gi097 Avatar answered Oct 22 '22 09:10

gi097


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 &lt;= 20
).@count &gt;= 1
like image 21
C. Moulinet Avatar answered Oct 22 '22 10:10

C. Moulinet