简体   繁体   中英

iOS Share extension not working on image urls

I have a share extension that uses those rules:

<dict>
    <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
    <integer>1</integer>
    <key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
    <integer>1</integer>
    <key>NSExtensionActivationSupportsImageWithMaxCount</key>
    <integer>10</integer>
    <key>NSExtensionActivationSupportsText</key>
    <integer>1</integer>
</dict>

It works perfectly for normal websites and images but I can't parse image urls like this : ( http://www.zappos.com/images/z/3/3/5/4/0/3/3354034-p-2x.jpg ). I tired to add other rules but still my share extension won't appear when I open this website with Safari and click share.

But if I make rule TRUEPREDICATE, my share extension can parse the site.

What I am doing wrong? Thanks

You did nothing wrong,it's just because the common keys (of the following chart) defined by Apple cannot include all cases.

在此输入图像描述

For your case , you have to write your own NSPredicate String as Apple suggested here: Declaring Supported Data Types for a Share or Action Extension

I changed apple's example like this:

<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
       </string>
    </dict>

You can change public.image to any other Uniform Type Identifiers .

Some of the common UTIs are listed below:
在此输入图像描述

Building off of wj2061's answer, the following predicate will grab any and all attachments supplied by the host app.

<key>NSExtensionActivationRule</key>
<string>SUBQUERY (
    extensionItems,
    $extensionItem,
    SUBQUERY (
        $extensionItem.attachments,
        $attachment,
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.item" ||
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.content"
    ).@count == $extensionItem.attachments.@count
    ).@count > 0
</string>

I resolved this issue by

<key>NSExtensionActivationRule</key>
            <string>SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                $extensionItem.attachments,
                $attachment,
                (
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO &quot;com.adobe.pdf&quot;
                || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO &quot;public.image&quot;
                || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO &quot;public.url&quot;
                )
                ).@count == $extensionItem.attachments.@count
                ).@count > 0</string>

The last line @count > 0 did the trick for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM