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?
Looks like a predicate could fix it:
https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html
Action Extension activation rule predicate doesn't hide the action when multiple of the same type is selected
How do I set NSExtensionActivationRule predicates?
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 "public.image" ).@count == 1 ).@count == 1</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.ui-services</string>
</dict>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With