Skip to content

Instantly share code, notes, and snippets.

@kristofer
Last active July 28, 2020 19:31
Show Gist options
  • Save kristofer/560ba94600351f47a495 to your computer and use it in GitHub Desktop.
Save kristofer/560ba94600351f47a495 to your computer and use it in GitHub Desktop.
iOS Share Extension NSPredicate trick
//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>
@KatkayApps
Copy link

can you please explain what exactly having these lines on the info.plist does for your extension? thanks in advance.

@abhijeetkmr
Copy link

when both "public.url" and "com.adobe.pdf" included-> it only supports one. Any different approach to fix this

@HarelM
Copy link

HarelM commented Jul 28, 2020

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