I want to allow my users to share photos and videos into my app's social stream from the Photos, Clips and other apps. I know that an iOS Sharing Extension is the way to go and I've gotten the info.plist all set to allow me to get one of either, but I need to restrict the video file size to 1.5MB or so. I'll reencode it to get it a little smaller, but that is beside the point. :-) But I am stuck on configuring the predicate to limit the extension to firing on video files below this size. Here is what I have so far:
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
(
ANY ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg-2000"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.compuserve.gif"
|| (ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie"
AND 1500000 > $attachment.filesize)
)
).@count == 1
).@count == 1</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
Note that doing > 1500000 causes a build error. I have a weird feeling this is broken or won't work.
Thanks!
f-
In the snippet you posted I presume that
$attachment
is expected to be of type
NSItemProvider
. But that type has no
filesize
property, or anything similar, so I can’t see how this would work.
Regardless, are you sure you want to filter yourself out based on file size? It’s reasonable to filter yourself based on file type because that’s clearly visible to the user. But filtering on file size is likely just to confuse folks: when they select video A your extension shows up but when they select video B it doesn’t. It might be a better UE to actually accept a large video and then tell the user why they can’t upload it.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"