5

Using Swift5.3.2, iOS13.0,

My Share Extension is working for images and videos.

However it does not work for PDFs.

The problem is that my App is not visible in the list of Share-Apps for a PDF document that I am trying to share with my App.

I know that the rules must be correctly set inside the info.plist.

I tried the following two attempts - but both without success !

Can anybody tell me what a PDF share extension needs in iOS ?

attempt 1: Info.plist

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsFileWithMaxCount</key>
            <integer>20</integer>
            <key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
            <integer>1</integer>
            <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
            <integer>1</integer>
            <key>NSExtensionActivationSupportsImageWithMaxCount</key>
            <integer>100</integer>
            <key>NSExtensionActivationSupportsMovieWithMaxCount</key>
            <integer>25</integer>
        </dict>
    </dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.share-services</string>
    <key>NSExtensionPrincipalClass</key>
    <string>CustomShareNavigationController</string>
</dict>

attempt 2: Info.plist

<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 "com.adobe.pdf"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.file-url"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
                    || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
                ).@count == $extensionItem.attachments.@count
        ).@count == 1
        </string>
    </dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.share-services</string>
    <key>NSExtensionPrincipalClass</key>
    <string>CustomShareNavigationController</string>
</dict>
iKK
  • 6,394
  • 10
  • 58
  • 131
  • Hi, have you find a solution? I'm stuck here too :( And the Apple documentation isn't helpful. https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1 – sanghapark Mar 19 '21 at 06:51

1 Answers1

4

When you initiate a share for a PDF in Safari, it will actually consider 2 input items: the PDF and the URL. Since your NSExtensionActivationRule predicate specifically states that @count == 1, it will return false as there is more than 1 element that matches your predicate. The fix is thus to change @count == 1 to @count >= 1 or whichever logic best fits your application.

Updated query that worked for me:

<key>NSExtensionActivationRule</key>
<string>
SUBQUERY (
    extensionItems,
    $extensionItem,
        SUBQUERY (
            $extensionItem.attachments,
            $attachment,
            ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.pdf"
            || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.file-url"
            || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
            || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
            || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
        ).@count == $extensionItem.attachments.@count
).@count >= 1
</string>
Arthur
  • 528
  • 4
  • 9
  • 1
    For some reason on iOS 15, this doesn't show the pdf attachment, however this works on macOS Monterey share extension. Any help would be much appreciated – user1046037 Nov 21 '21 at 10:17