Article

Adding Sticker Packs and iMessage Apps to Effects in Messages and FaceTime

Enable your Sticker pack or iMessage app in the media context.

Overview

In iOS 12 and later, Sticker packs and iMessage apps can appear in multiple contexts.

MSMessagesAppPresentationContext.messages context

The Sticker pack or iMessage app appears in the Messages app. This is the default behavior, seen in iOS 11 and earlier.

MSMessagesAppPresentationContext.media context

The Sticker pack or iMessage app appears in effects in Messages and FaceTime.

To access effects, the user taps the effects button in the Messages camera or FaceTime. The system then displays all the iMessage apps and Sticker packs that support the media context. The user can launch an app, and use it to add images or stickers to the camera.

By default, Sticker packs automatically support both the MSMessagesAppPresentationContext.messages and MSMessagesAppPresentationContext.media contexts. However, iMessage apps only appear in the MSMessagesAppPresentationContext.messages context. To enable support for the MSMessagesAppPresentationContext.media context, set the MSSupportedPresentationContexts key in your extension’s Info.plist file.

A Sticker pack or iMessage app’s context limits its available features. For example, In the MSMessagesAppPresentationContext.messages context, the user can peel off stickers and attach them to any bubbles in the current conversation. Your app can also programatically send stickers, images, text, or interactive messages.

In the MSMessagesAppPresentationContext.media context, your app appears in effects in Messages and FaceTime. Therefore, the system limits your app to features that make sense over a photo or video. For instance, the user can’t play an interactive game while taking a photo; however, they can add stickers or images to the picture.

Specify the Supported Contexts

To specify the supported contexts:

  1. Open the Info.plist file for your Sticker pack or iMessage app extension.

  2. Add the MSSupportedPresentationContexts key, using an Array type.

  3. Add String values for the supported contexts. For the MSMessagesAppPresentationContext.messages context, add the MSMessagesAppPresentationContextMessages value. For MSMessagesAppPresentationContext.media, add MSMessagesAppPresentationContextMedia.

Figure 1 shows an iMessage app that supports both the MSMessagesAppPresentationContext.messages and MSMessagesAppPresentationContext.media contexts.

A screenshot showing support for both the messages and media contexts in the Info.plist file.

All iMessage apps must support the MSMessagesAppPresentationContext.messages context. You can optionally add the MSMessagesAppPresentationContext.media context, but you cannot make a media-only app.

For more information on setting Info.plist keys, see Edit property lists.

Work with the Media Context

The MSMessagesAppPresentationContext.media context supports only a subset of the features provided by the Messages framework. Users can peel stickers from a sticker browser view, and place them in the Messages camera or FaceTime. They can reposition, resize, rotate, or remove stickers from the viewfinder.

iMessage apps can also insert stickers or images into the viewfinder using the insert(_:completionHandler:) or insertAttachment(_:withAlternateFilename:completionHandler:) methods. However, if the attachment is not an image supported by MSSticker, then the insertAttachment(_:withAlternateFilename:completionHandler:) method fails with an MSMessageErrorCode.apiUnavailableInPresentationContext error.

Additionally, you cannot insert interactive messages or text into the media context. You also cannot send items automatically. Therefore, the following methods from the MSConversation class are not available:

If you call these methods, they fail with an MSMessageErrorCode.apiUnavailableInPresentationContext error.

Additionally, because you can’t send or receive interactive messages, the system never calls the following methods in the MSMessagesAppPresentationContext.media context:

Finally, the MSMessagesAppPresentationContext.media context is already inside the Messages camera or FaceTime; therefore, you cannot display another camera inside the current viewfinder.

Detect the Current Context

Use the MSMessagesAppViewController object’s presentationContext property to determine your iMessage app’s current context. Enable only the features that make sense in that context.

if presentationContext == .messages {
    // The system is presenting your iMessage app inside the Messages app.
    // You have full access to the Messages framework.
    // You can insert or send stickers, text, attachments, or interactive messages.
} else if presentationContext == .media {
    // The system is presenting your iMessage app in effects.
    // You can only insert stickers and images.
}