iOS AppExtension:如何结合NSExtensionActivationRule和NSPredicate

Pow*_*r78 4 ios ios-app-extension

我目前正在开发包含Share扩展的iOS应用程序.

我意识到 NSExtensionActivationSupportsImageWithMaxCount密钥不允许我在Safari下的.jpeg或.png URL("public.image"UTI,kUTTypeImage)上激活我的Share扩展(即:一个imgur链接).

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

我填写了一个关于雷达的错误,如果它不被通缉(甚至facebook,twitter等...都没有在这个URL上激活)

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

所以我必须将密钥翻译成UTI

到目前为止,我已翻译:
- NSExtensionActivationSupportsFileWithMaxCount"public.file-url" kUTTTypeFileURL
- NSExtensionActivationSupportsMovieWithMaxCount"public.movi​​e" kUTTypeMovie
- NSExtensionActivationSupportsText"public.text" kUTTypeText
- NSExtensionActivationSupportsWebURLWithMaxCount"public.url"kUTTypeURL

但我找不到类型翻译:

  • NSExtensionActivationSupportsWebPageWithMaxCount,"public.HTML"是kUTTypeHTML吗?

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

Her*_*7ea 14

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

    NSExtensionItem *item = extensionContext.inputItems.firstObject;

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

        if ( itemProvider )
        {
            NSArray *registeredTypeIdentifiers = itemProvider.registeredTypeIdentifiers;
            NSLog( @"registeredTypeIdentifiers: %@", registeredTypeIdentifiers );
        }
     }`
Run Code Online (Sandbox Code Playgroud)

这将为您提供要共享的文档的所有类型(例如:"public.url").由于多种类型,我的谓词变得有点复杂:

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
Run Code Online (Sandbox Code Playgroud)

这基本上寻找图像的任何文件类型(除了adobe psd),pdf,txt,csv或doc/docx.它还允许一次共享1个文档.

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

  • 在编写自己的谓词字符串时,请注意"`'确保**不要**'错误地使用```.你会惊讶于你可以在这些问题上失去的时间. (2认同)