iOS AppExtension:如何结合NSExtensionActivationRule和NSPredicate
我目前正在开发一个包含共享扩展的iOS应用程序。
我意识到, NSExtensionActivationSupportsImageWithMaxCount
键不允许我激活我的共享扩展名.jpeg或.pngurl(“public.image”UTI,kUTTypeImage)在Safari(即imgur链接)下。
如果我切换到NSActivationRule = TRUEPREDICATE,我仍然可以激活并testing我的扩展名,但是对于已发布的应用程序是禁止的。
我填写了一个雷达的情况下,它不是(甚至脸谱,微博等没有激活这个url)
现在,我想将下面的键和“public.image”结合在NSPredicatestring中,如文档所述( 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.movie” kUTTypeMovie
– NSExtensionActivationSupportsText
为“public.text” kUTTypeText
– NSExtensionActivationSupportsWebURLWithMaxCount
为“public.url” kUTTypeURL
但我没有findtypes翻译:
-
NSExtensionActivationSupportsWebPageWithMaxCount
,“public.HTML”是kUTTypeHTML?
有人已经在谓词中使用了这个键吗?
我最终做的是1)暂时允许TRUEPREDICATE,并使用这样的逻辑
NSExtensionItem *item = extensionContext.inputItems.firstObject; if ( item ) { NSItemProvider *itemProvider = item.attachments.firstObject; if ( itemProvider ) { NSArray *registeredTypeIdentifiers = itemProvider.registeredTypeIdentifiers; NSLog( @"registeredTypeIdentifiers: %@", registeredTypeIdentifiers ); } }`
这会给你想要共享的所有文档types(例如:“public.url”)。 由于多种types,我的谓词变得有点复杂:
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
这基本上寻找任何图像的文件types(非Adobe PSD,PDF格式,TXT,CSV或DOC / DOCX)。 它也只允许一次共享一个文件。
它看起来像kUTTypeImage包含PSD – 因此我阻止该格式(“com.adobe.photoshop-image”)。