iOS Share extension not working on image urls

为君一笑 提交于 2019-12-05 18:40:42

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>
wj2061

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:

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.

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