iOS AppExtension:如何结合NSExtensionActivationRule和NSPredicate [英] iOS AppExtension : How can I Combine NSExtensionActivationRule and NSPredicate

查看:2433
本文介绍了iOS AppExtension:如何结合NSExtensionActivationRule和NSPredicate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个包含Share扩展名的iOS应用程序。

I am currently developing an iOS application containing a Share extension.

我意识到
NSExtensionActivationSupportsImageWithMaxCount key不允许我在Safari下的.jpeg或.png URL(public.imageUTI,kUTTypeImage)上激活我的Share扩展名(即:一个imgur链接)。

I realized that the NSExtensionActivationSupportsImageWithMaxCount key doesn't allow me to activate my Share extension on .jpeg or .png URLs ("public.image" UTI, kUTTypeImage) under Safari (ie : an imgur link).

如果我切换到NSActivationRule = TRUEPREDICATE,我仍然可以激活并测试我的扩展程序,但禁止发布的应用程序。

I can still activate and test my extension if I switch to a NSActivationRule = TRUEPREDICATE, but it is forbidden for a released app.

我填写了一个错误在雷达的情况下,它不被通缉(甚至Facebook,推特等...没有激活此URL)

I filled a bug on radar in case of it wasn't wanted (even facebook, twitter, etc... aren't activated on this URLs)

现在,我想如文档所述,将下面的键和public.image组合在一个NSPredicate字符串中( https://developer.apple.com/library/ios/documentation/General /Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW8

Right now, I would like to combine the folowing keys and the "public.image" in a NSPredicate string as the documentation says (https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW8)

所以我必须将密钥翻译为一个UTI

So I have to translate the keys to a UTI

到目前为止,我已翻译:

- NSExtensionActivationSupportsFileWithMaxCount topublic.file -url kUTTTypeFileURL

- NSExtensionActivationSupportsMovieWithMaxCount topublic.movi​​e kUTTypeMovie

- NSExtensionActivationSupportsText 改为public.text kUTTypeText

- NSExtensionActivationSupportsWebURLWithMaxCount 改为public.url kUTTypeURL

So far I have translated :
- NSExtensionActivationSupportsFileWithMaxCount to "public.file-url" kUTTTypeFileURL
- NSExtensionActivationSupportsMovieWithMaxCount to "public.movie" kUTTypeMovie
- NSExtensionActivationSupportsText to "public.text" kUTTypeText
- NSExtensionActivationSupportsWebURLWithMaxCount to "public.url" kUTTypeURL

但我找不到以下类型翻译:

But I don't find the type translation for :


  • NSExtensionActivationSupportsWebPageWithMaxCount ,public.HTML是kUTTypeHTML吗?

  • NSExtensionActivationSupportsWebPageWithMaxCount, "public.HTML" is it kUTTypeHTML ?

有人已经在谓词中使用了这个键吗?

Does somebody already used this keys inside a predicate ?

推荐答案

我最终做的是1)暂时允许TRUEPREDICATE,并使用这样的逻辑`

What I ended up doing is 1) allowing TRUEPREDICATE temporarily, and using some logic like this`

    NSExtensionItem *item = extensionContext.inputItems.firstObject;

    if ( item )
    {
        NSItemProvider *itemProvider = item.attachments.firstObject;

        if ( itemProvider )
        {
            NSArray *registeredTypeIdentifiers = itemProvider.registeredTypeIdentifiers;
            NSLog( @"registeredTypeIdentifiers: %@", registeredTypeIdentifiers );
        }
     }`

这将为您提供文件的所有类型你想分享(例如:public.url)。由于多种类型,我的谓词变得有点复杂:

This will give you all the types of the document you want to share (example: "public.url"). Because of the multiple types, my predicate became a little complex:

SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                $extensionItem.attachments,
                $attachment,

                (
                           ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.pdf"
                        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
                        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.plain-text"
                        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
                        || 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 "com.compuserve.gif"
                        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.bmp"
                        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.word.doc"
                        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.openxmlformats.wordprocessingml.document"
                        || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.comma-separated-values-text"
                )
                AND
                (
                     NOT ( ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.photoshop-image" )
                )

    ).@count == $extensionItem.attachments.@count
).@count == 1

这基本上会查找图像的任何文件类型(adobe psd除外),pdf,txt,csv或DOC / DOCX。
它也只允许一次共享1个文档。

This basically looks for any file type for image (other than adobe psd), pdf, txt, csv or doc/docx. It also only allows 1 document to be shared at a time.

看起来kUTTypeImage包含PSD - 因此我阻止了该格式(com.adobe .photoshop-image)。

It looks like kUTTypeImage includes PSD - hence my blocking of that format ( "com.adobe.photoshop-image" ).

这篇关于iOS AppExtension:如何结合NSExtensionActivationRule和NSPredicate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆