-->

NSExtension Share Extension limit Photos count

2020-08-01 01:39发布

问题:

I have developed a Share Extension and import Photos and Notes from Photos and Notes App. I want to limit the count of Photos which can be import to only 10 but for Photos i am able to select unlimited photos. Below is the query from info.plist of extension. Can anyone look into it and guide me to correct query.

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <string>SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
            $extensionItem.attachments,
            $attachment,
            ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
            ).@count == $extensionItem.attachments.@count).@count == 1
            OR
            SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, SUBQUERY($attachment.registeredTypeIdentifiers, $uti, NOT $uti UTI-CONFORMS-TO "public.url" AND NOT $uti UTI-CONFORMS-TO "public.file-url" AND $uti UTI-CONFORMS-TO "public.plain-text").@count &gt;= 1).@count &gt;= 1).@count &gt;= 1
        </string>
    </dict>

回答1:

Got the answer. The change is for line @count == $extensionItem.attachments.@count).@count == 1 to
@count <= 10).@count >= 1 Which says your count should be <=10 and >=1

 <dict>
        <key>NSExtensionAttributes</key>
        <dict>
            <key>NSExtensionActivationRule</key>
            <string>SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                $extensionItem.attachments,
                $attachment,
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
                ).@count &lt;= 10).@count &gt;= 1
                OR
                SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, SUBQUERY($attachment.registeredTypeIdentifiers, $uti, NOT $uti UTI-CONFORMS-TO "public.url" AND NOT $uti UTI-CONFORMS-TO "public.file-url" AND $uti UTI-CONFORMS-TO "public.plain-text").@count &gt;= 1).@count &gt;= 1).@count &gt;= 1
            </string>
        </dict>


回答2:

IN ShareExtension Info add

<key>NSExtension</key>
    <dict>
        <key>NSExtensionAttributes</key>
        <dict>
            <key>NSExtensionActivationRule</key>
            <dict>
                <key>NSExtensionActivationSupportsImageWithMaxCount</key>
                <integer>1</integer>
            </dict>
        </dict>