2014-10-06 113 views
4

我目前正在開發一個包含Share擴展的iOS應用程序。iOS AppExtension:我如何結合NSExtensionActivationRule和NSPredicate

我意識到 NSExtensionActivationSupportsImageWithMaxCount鍵不允許我在Safari(ie:imgur鏈接)下的.jpeg或.png URL(「public.image」UTI,kUTTypeImage)上激活我的Share擴展。

如果我切換到NSActivationRule = TRUEPREDICATE,但仍然可以激活並測試我的擴展,但它對於已發佈的應用程序是被禁止的。

我填的錯誤雷達在這情況下,不希望(甚至是Facebook,微博等..都不會在這個網址激活)

現在,我想結合如下因素按鍵和一個NSPredicate字符串作爲文檔中的「public.image說:」(https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW8

所以我要鑰匙翻譯爲UTI

到目前爲止,我已經翻譯:
- NSExtensionActivationSupportsFileWithMaxCount「公開.file-url「kUTTTypeFileURL
- NSExtensionActivationSupportsMovieWithMaxCount爲 「public.movi​​e」 kUTTypeMovie
- NSExtensionActivationSupportsText爲 「public.text」 kUTTypeText
- NSExtensionActivationSupportsWebURLWithMaxCount爲 「public.url」 kUTTypeURL

但我沒有找到類型翻譯:

  • NSExtensionActivationSupportsWebPageWithMaxCount,「public.HTML」是否是kUTTypeHTML?

有人已經在謂詞中使用了這個鍵嗎?

回答

12

我最終什麼事做的是1)允許TRUEPREDICATE是暫時的,並使用類似this`

NSExtensionItem *item = extensionContext.inputItems.firstObject; 

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

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

這一些邏輯會給你所有的類型,你要共享(例如文檔的:「公衆。 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") 
       ) 

    )[email protected] == [email protected] 
)[email protected] == 1 

這基本上看起來對於圖像的任何文件類型,PDF,TXT,CSV或DOC/DOCX(比Adobe PSD等)。 它也只允許一次共享1個文檔。

它看起來像kUTTypeImage包含PSD - 因此我阻止該格式(「com.adobe.photoshop-image」)。

+0

感謝您的分享! – hyouuu 2015-01-20 11:29:12

+2

在編寫自己的謂詞字符串時,請注意'''確保**不**錯誤地使用''' 您會驚訝於這類問題可能會導致您丟失的時間數 – 2016-03-10 12:26:19

+0

好的,Shumais UI Haq,這讓我感到很多次,通常是從Word文檔中剪切粘貼的。 – Herbal7ea 2016-03-16 16:39:38