Make your messaging app available for share sheet suggestions and use SiriKit intents to populate your app’s share extension.
Using the iOS share sheet, users can launch your messaging app instantly from a list of suggestions when sharing content like a link, image, video, or file. The share sheet suggests conversations with people in apps that the user interacts with frequently, and updates its suggestions over time based on the user’s favorite apps and conversations. Figure 1 shows suggestions that include a mix of apps and conversations with contacts.
To allow iOS to include conversations from your messaging app in the list of suggestions:
Add a share extension to your app as described in Understand Share Extensions.
Declare support for the
INSendin your messaging app and its share extension.
As the user selects an app from the list of suggestions, the app’s sharing interface, implemented as a share extension, accesses additional metadata. iOS provides the
INSend for you to prepopulate the interface of your app’s share extension.
For example, you can access the
conversation property and preselect a conversation with which to share content so the user doesn’t need to search for a contact in a list, or type a friend’s name. Figure 2 shows an app’s sharing interface using the default system UI that’s based on an
SLCompose, with the recipient (Juan Chavez) already filled in.
Add a Share Extension to Your App
To add a share extension to your app, open your app’s project in Xcode and select File > New > Target from the menu bar. Xcode presents a sheet that contains templates for different kinds of targets. Select the share extension template from the iOS pane and follow the steps in Xcode’s interface to add one to your app. To learn more, see Understand Share Extensions in the App Extension Programming Guide.
Support the Send Message Intent
Open the Share extension’s
Info, and expand the NSExtension and NSExtensionAttributes keys. Next, add a new entry with the
Intents key and select
Array for its value type. Add the string
INSend as a new value to the array to declare support for the
INSend intent type, as shown in Figure 3.
To make debugging easier, the value of NSExtensionActivationRule is set to
TRUEPREDICATE when you first add a share extension using Xcode’s template. Replace it with valid activation rules as described in Declaring Supported Data Types for a Share or Action Extension before submitting your app for review.
Donate a Send Message Intent
INSend when the user sends a message in your app and its share extension, and not in any other circumstances. For example, don’t donate an intent when the user hasn’t actually sent a message.
As you initialize the
INSend object, provide metadata that will be available later when the user choses your app’s share extension from the list of suggestions. The following code donates an
INSend with a
conversation, and an
When iOS includes a conversation within your app as a suggestion in the share sheet, it displays your app’s icon along with the
INImage you associated with your
INSend. If there’s no
INImage set on the intent, iOS uses the
image property from the
INPerson object for each recipient. If the
nil, iOS looks up the corresponding contact in the Contacts app using the person’s
contact. The share sheet then uses the contact’s image.
Populate Your Share Extension’s Interface with Metadata
When the user selects your app from the list of suggestions, you can access the metadata that you created when your app donated the
INSend. Use it to populate your share extension’s interface.
The following code listing shows a template implementation for an
SLCompose subclass. It accesses the
intent property, makes sure it’s an
INSend, and uses the intent’s
conversation to create a new
Recipient object. It then uses the
Recipient object to populate the share extension’s interface in the