iOS AppExtension : How can I Combine NSExtensionActivationRule and NSPredicate

后端 未结 1 1238
迷失自我
迷失自我 2020-12-10 08:23

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

I realized that the NSExtensionActivationSupportsImageWithMaxCount key doesn\

相关标签:
1条回答
  • 2020-12-10 08:49

    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 );
            }
         }`
    

    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
    

    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.

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

    0 讨论(0)
提交回复
热议问题