How to implement "Share with apps" functionality in iOS 17?

507 views Asked by At

I am trying to create an app extension that i can use in a shortcut using the "share with apps" action. I have the extension created AND it shows up in the regular share sheet for just sharing anything. However, when i go into the shortcut app to create an automation that use the "Share with apps" action and try to select my app, i only see health, linkedin, slack, reminders, and a few other apps. What is different about this share functionality vs regular share functionality?

Does anyone know how to make their app show up in the list of apps you can select when you are in shortcuts using "Share with apps" action?

To be more specific. here is example. Image of pinterest showingOne image attached shows the shortcut of taking screenshot and opening pinterest which still in the original app (in this example it was the Notes app).

The other screenshot shows my shortcut setup.Image of shortcuts The goal here is for me to select my app instead of pinterest. I dont see my app listed in the list of apps to select. I have tried app intents, intents, share extensions but clearly doing something wrong. Thanks!

Update

OK so i have my ActionExtension working BUT only in simulator. When i go to try on my device i do not see it. Attached shows simulator. Simulator

Also, when i try to run the shortcut i get this error error Does anyone know why this would be the case? My updated rule is SUBQUERY ( extensionItems, $extensionItem, SUBQUERY ( $extensionItem.attachments, $attachment, ( ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image" ) ).@count == $extensionItem.attachments.@count ).@count == 1

2

There are 2 answers

1
Pierre Janineh On

Have you included the corresponding UTI types in your info.plist?

For example, if your extension supports:

  • text > public.text
  • or, images > public.image

info.plist

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Public Text</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.text</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Public Image</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.image</string>
        </array>
    </dict>
</array>
4
Sparga On

A share extension is indeed the way to go to achieve that. Based on your screenshots, it appears that you already implemented the extension.

I re-created the same shortcut as yours in an iOS simulator and actuall managed to get a share extension working using the same NSActivationRule you used in your question. That being said, there is a simpler way to do the same with the following configuration:

In the Info.plist of your share extension target, you should have something like this:

<key>NSExtension</key>
<dict>
    <key>NSExtensionMainStoryboard</key>
    <string>MainInterface</string>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.share-services</string>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsImageWithMaxCount</key>
            <integer>1</integer>
        </dict>
    </dict>
</dict>
  • NSExtensionPointIdentifier defines the type of extension, here a share extension,
  • NSExtensionMainStoryboard points to the storyboard containing your share extension UI,
  • NSExtensionActivationRule defines when the share sheet should show your extension based on the UTI type of the data being shared.

Here the activation rule is set to NSExtensionActivationSupportsImageWithMaxCount with a count of one. This means that the extension only shows up when a single image is being shared, which is what the shortcut is doing. Please note that this is simply a shorthand doing the same thing as the activation rule from your question.

Testing on simulator

Another thing to take into account is that Xcode sometimes have issues deploying the latest version of an extension on a simulator or device. The most reliable way to test I found to test this is to run the extension target and then select the Shortcut app as the host application.

Menu to select host application for the extension

Testing on a device

Finally, on a device, it looks like the "Share with apps" step only list applications signed with a distribution certificate. Using a TestFlight build is probably the way to go to test it on your device once it works in your simulator.