7

I want my extension support text, url, video and 10 images.

I have configured plist as below: enter image description here

This work fine but I want my extension does not support image and video at the same time.

I understand that I'll most probably have to build a "SUBQUERY(..)" statement. My predicate like this:

SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,(
     NOT ( ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
           AND ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie")
     ) AND (
           ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.plain-text"
        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text")
).@count < 10
).@count == 1

But it doesn't work for me. How do I use in this case. Thanks for any help!

Buvaty
  • 71
  • 4

4 Answers4

3

You can use Parth Adroja's answer for sharing images or videos based on a particular count. In my particular case, the extension was supposed to share either 4 images or 1 video and they were mutually exclusive.

Here is what I did.

  1. The first subquery selects images of type jpeg or png up to 4 counts and checks whether the count of video(s) selected is zero.
  2. Adding a OR condition to the first subquery, we now check if only 1 video is selected and no image is selected.
  3. Adding a third sub query to support text and web urls.
<key>NSExtensionActivationRule</key>
<string>
    SUBQUERY (
      extensionItems,
      $extensionItem,
      (
        SUBQUERY (
          $extensionItem.attachments,
          $attachment,
          ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
          ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
        ).@count &lt;= 4
        AND
        SUBQUERY (
          $extensionItem.attachments,
          $attachment,
          ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
        ).@count == 0
      )
      OR
      (
        SUBQUERY (
          $extensionItem.attachments,
          $attachment,
          ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
          ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
        ).@count == 0
        AND
        SUBQUERY (
          $extensionItem.attachments,
          $attachment,
          ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
        ).@count == 1
      )
      OR
      (
        SUBQUERY (
         $extensionItem.attachments,
         $attachment,
           ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text" OR
           ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.plain-text" OR
           ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" OR
        ).@count == 1
      )
    ).@count &gt;= 1
</string>

Midhun Darvin
  • 1,236
  • 14
  • 24
1

Here's one I just used for myself. This only allows 1 item, either any video type or any image type. I modified an example from apple's documentation.

SUBQUERY (
    extensionItems,
    $extensionItem,
    SUBQUERY (
        $extensionItem.attachments,
        $attachment,
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image" ||
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
    ).@count == 1
).@count == 1

For easy of use copying directly into the plist:

SUBQUERY (extensionItems, $extensionItem, SUBQUERY ( $extensionItem.attachments, $attachment, ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image" || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie" ).@count == 1).@count == 1
dsringari
  • 104
  • 2
0

You don't need to build subquery. In info.plist of your extension there will be NSExtension. And it will have NSExtension as truepredicate. Edit that plist file and add NSExtensionActivationRule. Add the key which you require accordingly. For keys details click here

enter image description here

Parth Adroja
  • 13,198
  • 5
  • 37
  • 71
  • 1
    Thanks!, but I give notice that TRUEPREDICATE only use for develop. If app include the string TRUEPREDICATE, the app will be rejected. [Detail](https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html) – Buvaty Dec 23 '15 at 01:26
  • @LạcBùi you are absolutely correct but you can change that value i have attached screenshot please check that and apply accordingly. – Parth Adroja Dec 23 '15 at 04:53
  • I have used plist file like that. But I want to know exactly my extension does not support both video and image. Just like you tap selected video and image at the same time, the app icon will disappear – Buvaty Dec 23 '15 at 06:54
  • I have just updated my question, I'm sorry it isn't clear – Buvaty Dec 23 '15 at 07:05
  • @Buvaty, probably you could use `NSExtensionActivationDictionaryVersion` or `NSExtensionActivationUsesStrictMatching` – Slav Nov 16 '16 at 15:51
0

Try this one to share limited images, docs and video

   SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
            $extensionItem.attachments,
            $attachment,
            ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.mpeg-4"
            ).@count == 0).@count == 1
            AND
            SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
            $extensionItem.attachments,
            $attachment,
            ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
            ).@count &lt;= 15).@count &gt;= 1
            AND
            SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
            $extensionItem.attachments,
            $attachment,(
               ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.pdf"
            || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.waveform-audio"
            || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
            || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.data"
            AND NOT ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
            )
            ).@count &lt;= 3
            ).@count == 1
Brtgmaden
  • 839
  • 7
  • 8