5

I have implemented a share extension for an iOS App. The extension works with images and videos successfully.

Now I am looking for a way to make the extension work for more file types, such as PDF's, Spreadsheets (Excel, Pages, etc.), Documents (MS Word, other similar types), Presentations (Powerpoint, Pages, etc.), simple text files (Txt, xml, .c, .h, any others) and web page URLS.

The problem is that I want to be able to activate the extension with the following rules:

1. Images and Videos can be selected together for a total of 25 items, with maximum 25 images and/or maximum of 5 videos. So we can have 1-25 images only OR 1-5 videos only OR 20 images and 5 videos OR any combination as long as total items stays less than or equal to 25 and Videos stay less than or equal to 5

2. No other types can be selected if Image/s or Video/s are selected.

3. PDF maximum of 1 with no other types selected.

4. Spreadsheets maximum of 5 with no other types selected.

I have been trying to achieve this by using a custom SUBQUERY for NSExtensionActivationRule but have not been able to figure it out.

I have gone through many stack overflow posts and also a couple posts not on stack overflow and also through the Apple Documents, which do not have any thing more than simple examples, but I havent been able to successfully write a SUBQUERY that fits my requirements.

For example, I tried to write the following SUBQUERY that should activate the extension only when Images are selected and specifically ignore PDFs, presentations, audios, movies and text files. But the extension get activated for texts and PDFs, also probably for the rest of the ignored items too, though I didnt check each one specifically.

SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
            $extensionItem.attachments,
            $attachment,
        (
                       ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.fax"       
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg-2000"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.tiff"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.camera-raw-image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.apple.pict"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.apple.macpaint-image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.xbitmap-image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.apple.quicktime-image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.apple.icns"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.photoshop-​image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.illustrator.ai-​image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.bmp"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.ico"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.truevision.tga-image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.sgi.sgi-image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.ilm.openexr-image"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.kodak.flashpix.image"
        )
        AND
                (
                        NOT ( ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.composite-content" 
                 || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
                 || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.presentation"
                 || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.audio”
                 || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie”
            )
                )
).@count == $extensionItem.attachments.@count
).@count <=50

Can someone point me in the right direction? If I can get a SUBQUERY to work with the rules, given above, then I can basically just extend it to work with other file types too.

Shumais Ul Haq
  • 1,427
  • 1
  • 15
  • 26
  • I'm not familiar with `NSExtensionActivationRule`, so this might be a red-herring, but I wonder whether the final line of your SUBQUERY is the problem: If the attachments fail the inner subquery criteria, the count of extensionItems will be zero - which is <= 50 and so the complete predicate is true. Try with `.@count == extensionItems.@count`. – pbasdf Mar 11 '16 at 10:16
  • From what limited understanding I have about this, the `SUBQUERY` should not allow the extension to be activated in the case of any items that are not images because it explicitly contains the types that it needs to ignore, I do not think that the final count will matter in this case. The final count should only be effected by items that are Images. – Shumais Ul Haq Mar 11 '16 at 10:29

0 Answers0