Last active
July 28, 2020 19:31
-
-
Save kristofer/560ba94600351f47a495 to your computer and use it in GitHub Desktop.
iOS Share Extension NSPredicate trick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//After way, way, way too much trial and error, I finally found a way to create the Share Extension for documents that I was seeking. | |
// It's not obvious what the NSPredicate should be, but then harder was a lack of example of how to actually use the predicate | |
// within the Info.plist file of an iOS (8.2+) share extension | |
<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 "com.adobe.pdf" | |
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" | |
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.file-url" | |
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.plain-text" | |
) | |
).@count == $extensionItem.attachments.@count | |
).@count == 1</string> | |
</dict> | |
<key>NSExtensionMainStoryboard</key> | |
<string>MainInterface</string> | |
<key>NSExtensionPointIdentifier</key> | |
<string>com.apple.share-services</string> | |
</dict> |
when both "public.url" and "com.adobe.pdf" included-> it only supports one. Any different approach to fix this
Is there a way to get the public.url value in the subquery? I would like to filter out irrelevant sites... Has anyone managed to do it or I must use the using the code to handle this? I'm using cordova so I have limited access to the objective-c/swift code...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you please explain what exactly having these lines on the info.plist does for your extension? thanks in advance.