6

As the title states, I want my extension to show up when the users share *.wav files

I've come across the following apple documentation: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW8

I'm trying to figure out how to actually use what is mentioned in the documentation to do so. The documentation leaves me with the feeling I have most if not all the pieces I need, but not how they go together.

I understand that I'll most probably have to build a "SUBQUERY(..)" statement, but where does it go? How do I use it?

LostBalloon
  • 1,608
  • 3
  • 15
  • 31

2 Answers2

15

I ended up doing the following:

for the NSExtensionActivationRule key, I changed the type from Dictionary to String and entered the following string (you can keep the formatting, doesn't need to be all inline):

SUBQUERY (
    extensionItems,
    $extensionItem,
    SUBQUERY (
        $extensionItem.attachments,
        $attachment,
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image" ||
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.movie" ||
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.audio"
    ).@count == $extensionItem.attachments.@count
).@count >= 1

You only need the:

ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.audio"

but my extension also supports movies and images which is why it has those too (left it in for those that may be curious how to support more than one. Note that I've decided to support more audio options than just waves as I was initially inquiring about. The types can be looked up here: Uniform Type Identifiers Reference

The first count check makes sure that every single selected item in the host app conforms with the extension.

The second count check, the one at the end is used to indicate that the extension accepts 1 or more items (that conform). If you wanted to only allow for 1 item at the time to be processed by your extension you would enter the following:

).@count == 1

or, if you wanted to allow for multiple items with an upper limit:

).@count < 4

or

).@count <= 3
toraritte
  • 6,300
  • 3
  • 46
  • 67
LostBalloon
  • 1,608
  • 3
  • 15
  • 31
  • Be sure to use `"` and **not** to use `”`, in your predicate string, by mistake. it will save you a lot of time and headache. – Shumais Ul Haq Mar 10 '16 at 12:27
  • why not to use just `public.data` instead of all these types in predicate? It works... – D4ttatraya Dec 24 '18 at 15:15
  • This does not work for `m4a` extension files. :( – Parth Feb 21 '21 at 16:04
  • `public.mpeg-4-audio` `MPEG-4 audio layer (.m4a)` `public.mpeg-4, public.audio`, my source of information: https://www.escapetech.eu/manuals/qdrop/uti.html – LostBalloon Feb 22 '21 at 17:08
  • @ParthTamane, like in the comments above, make sure you're quotes haven't been autocorrected by your text editor. This dates back to iOS 8 too, and I unfortunately can't really tell if some of the setup has changed or not. – LostBalloon Feb 22 '21 at 17:19
  • I did check that, my issue is this: https://stackoverflow.com/questions/49309019/share-extension-does-not-appear-in-capable-apps-if-nsextensionactivationrule-is Once I added in Import UTI, the extension m4a it shows up in share sheet. But after I select my app no view controller appears. – Parth Feb 22 '21 at 17:21
  • Changed it to `public.mpeg-4-audio` and removed impor type from apps info and the app still shows up in share sheet. But nothing pops up when I click on it. However long pressing icon gives an option to open in app. What's going on? Before I made any changes a small black box with cancel and post options was showing up... – Parth Feb 22 '21 at 17:35
  • OT: amazing how complicated Apple designed that. They could have just supported share extension specifying "audio/x-wave" but instead created this mess of a query language that can not even properly handle WAV files or extensions or mime-types. – philk Oct 05 '21 at 15:58
0

I case anyone is wondering how this will look like for a single item without the outer SUBQUERY:

SUBQUERY(
    $extensionItem.attachments, 
    $attachment, 
    ANY $attachment.registeredTypeIdentifiers 
    UTI-CONFORMS-TO "public.audio"
).@count = 1

Just replace UTI-CONFORMS-TO "public.audio" with UTI-CONFORMS-TO "public.image" or UTI-CONFORMS-TO "public.movie".

Parth
  • 2,682
  • 1
  • 20
  • 39