Get the iOS Share / Action extension to display for only one image

I have an action extension in an iOS application that I want to use only when the user uses a single image. The NSExtension key in my NSExtension is as follows.

 <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 valid activation rule is NSExtensionActivationSupportsImagesWithMaxCount with a value of 1 . However, the extension still appears when sharing other things. For example, it appears when I click the action button in Safari.

In the case of Safari, there is no image that needs to be pulled from the NSExtensionContext .

Does anyone know how to make my extension not appear in these cases?

+5
source share
2 answers

I was able to get this job 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> 
+2
source

Source: https://habr.com/ru/post/1260222/


All Articles