iOS Share extension not working on image urls

ぃ、小莉子 提交于 2019-12-22 09:38:16

问题


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


回答1:


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>



回答2:


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:




回答3:


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.



来源:https://stackoverflow.com/questions/38226283/ios-share-extension-not-working-on-image-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!