5

I have an action extension in an iOS app that I only want to be available when the user is sharing a single image. The NSExtension key in my info.plist looks like this.

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsImagesWithMaxCount</key>
            <integer>1</integer>
        </dict>
    </dict>
    <key>NSExtensionMainStoryboard</key>
    <string>MainInterface</string>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.ui-services</string>
</dict>

The only activation rule I am using is NSExtensionActivationSupportsImagesWithMaxCount with a value of 1. However, the extension still shows up when sharing other things. For example, it shows up when I hit the action button in Safari.

In the Safari case, there is no image to be pulled out of the NSExtensionContext.

Anyone have any idea how to get my extension to not show up in those cases?

Ross Kimes
  • 1,234
  • 1
  • 12
  • 34
  • Looks like a predicate could fix it: https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html – mattyb Nov 26 '16 at 22:30
  • http://stackoverflow.com/questions/34549427/action-extension-activation-rule-predicate-doesnt-hide-the-action-when-multiple – mattyb Nov 26 '16 at 22:32
  • http://stackoverflow.com/questions/28654593/how-do-i-set-nsextensionactivationrule-predicates – mattyb Nov 26 '16 at 22:32
  • Sorry for the 3 individual comments, but i feel like it's easier to read when separate. Those are 3 distinct links. – mattyb Nov 26 '16 at 22:33
  • That seemed to do the trick. It is strange that what I had did not work, but this solution was simple enough. Thanks! – Ross Kimes Nov 29 '16 at 05:10
  • Do you want to answer it or should i so i claim the bounty? Haha – mattyb Nov 29 '16 at 05:11
  • I put an answer there, but if you put one down I'll give you the bounty! – Ross Kimes Nov 29 '16 at 05:14
  • Thanks so much, I really need need the rep boost and I dont want your bounty to go waste! – mattyb Nov 29 '16 at 05:19
  • I think you have to manually award me the bounty on top of accepting my answer – mattyb Nov 29 '16 at 07:30

2 Answers2

2

Was able to get this working thanks to @Matthew-Bordas. The solution was to use a predicate.

<key>NSExtension</key>
<dict>
  <key>NSExtensionAttributes</key>
  <dict>
    <key>NSExtensionActivationRule</key>
    <string>SUBQUERY ( extensionItems, $extensionItem, SUBQUERY ( $extensionItem.attachments, $attachment, ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO &quot;public.image&quot; ).@count == 1 ).@count == 1</string>
  </dict>
  <key>NSExtensionMainStoryboard</key>
  <string>MainInterface</string>
  <key>NSExtensionPointIdentifier</key>
  <string>com.apple.ui-services</string>
</dict>
Ross Kimes
  • 1,234
  • 1
  • 12
  • 34