With iOS 10, Apple has opened up the Messages application to third-party developers through a new feature called iMessage apps. Developers can now create their own various types of apps, ranging from sticker packs to fully interactive interfaces, which create inline iMessage content.
In this tutorial I am going to introduce you to the new Messages framework and show you how to create your very own iMessage apps.
This tutorial requires that you are running Xcode 8 on OS X El Capitan or later and assumes that you are comfortable with creating a UIKit-based iOS application. If you're still getting started with iOS development, check out the iOS From Scratch With Swift tutorial series. Over the course of that series, you'll learn how to start developing for the iOS platform with in-depth articles and tutorials.
1. Ecosystem
The iMessage app ecosystem begins with a full App Store that is accessible to users through the Messages application. This store is completely separate from the regular iOS app store and will show only the iMessage-related apps.
iMessage apps exist as extensions to regular iOS applications, similar to things like Photos extensions and custom keyboards. The key difference is that, since the iMessage App Store exists on its own inside the Messages app, you can create an iMessage app without having to create an iOS app that goes on the user's home screen; the iMessage app is created as an extension of an effectively blank and invisible iOS app. It is important to note, however, that of course if you want to develop both an iOS and iMessage app, you can create an iMessage extension just like any other type of extension.
Lastly, while iMessage apps will only be available on iOS, their content will still be viewable on macOS and watchOS devices. In addition to this, users of watchOS 3 will be able to view their recently used stickers and send these to their contacts straight from an Apple Watch.
2. Basic Sticker Packs
For people who just want to create a quick and easy iMessage sticker pack, Xcode provides a template to do so without having to write any code at all! This will be a great tool to enable graphic artists with no programming knowledge at all to create a sticker pack.
Using the new Messages framework to create a sticker pack, you can create small, medium or large stickers. This size, however, applies for all stickers in your pack. You only need to provide the largest image size for each sticker in your pack, and the system will downscale your images when being displayed on other devices.
While not strictly enforced, here are the file sizes that Apple recommends for your sticker packs:
- Small: 100 x 100 pt @3x scale (300 x 300 pixel image)
- Medium: 136 x 136 pt @3x scale (378 x 378 pixel image)
- Large: 206 x 206 pt @3x scale (618 x 618 pixel image)
- Images can be no larger than 500 KB in file size.
- Images can be no smaller than 100 x 100 pt (300 x 300 pixels).
- Images can be no larger than 206 x 206 pt (618 x 618 pixels).
- Image files must be PNG, APNG, JPEG, or GIF format; PNG for static stickers and APNG for animated ones are recommended because they handle scaling and transparent backgrounds much better than JPEG and GIF respectively.
![]() |
You will see in the left sidebar of Xcode that you now have a Stickers.xcstickers asset catalog in your project. This folder will contain your iMessage application icon and all of the stickers in your pack. Adding stickers to your application is as easy as dragging them into the Sticker Pack folder of your asset catalog.
![]() |
![]() |
![]() |
To test your sticker pack, simply press the play button in the top-left corner of Xcode or press Command-R on your keyboard. Once the simulator has booted up, Xcode should present you with the following menu.
![]() |
![]() |
![]() |
![]() |
3. Custom Sticker Applications
For some use cases, the very basic functionality provided by the basic sticker application template may not quite be enough. Because of this, Apple also provides a way for you to create a more customised sticker pack application. If you want to follow along, create a new project called CustomStickerPack as shown at the start of this tutorial, but this time choose the iMessage Application template.
Once Xcode has created your project, you will see that you now have folders similar to that of an iOS app with an additional MessagesExtension folder. The top CustomStickerPack folder simply contains an asset catalog and Info.plist file for your "blank" iOS application. It is important that you provide all of the correct sized app icons in this asset catalog because iOS will still use it for things such as the user's storage usage settings.
The folder we are going to focus on is the MessageExtension folder, which at the moment contains the following files:
- MessagesViewController.swift which is the root view controller for your iMessage app's UI
- MainInterface.storyboard where you can design your app's interface easily
- Assets.xcassets which contains your iMessage app's icon files as well as any other image assets you need to use in your interface
- Info.plist for configuration values of your extension
For our example custom sticker application, we are just going to create our interface programmatically using the new MSStickerBrowserViewController class.
Open up your MessagesViewController.swift file, and you will firstly see that your MessagesViewController class is a subclass of MSMessagesAppViewController, which itself is a subclass of UIViewController. This means that all of UIKit is available for you to use in your iMessage applications.
The MSMessagesAppViewController class provides many callback methods which you can override to further customise the functionality of your application, but we don't need to worry about these in this tutorial. For now, just edit your class definition so that your class conforms to the MSStickerBrowserViewDataSource protocol:
- class MessagesViewController: MSMessagesAppViewController, MSStickerBrowserViewDataSource {
- ...
- }
Once you have added these files, add the following code to your MessagesViewController class:
- var stickers = [MSSticker]()
- func loadStickers() {
- for i in 1...2 {
- if let url = Bundle.main.urlForResource("Sticker \(i)", withExtension: "png") {
- do {
- let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "")
- stickers.append(sticker)
- } catch {
- print(error)
- }
- }
- }
- }
With this code we simply create an MSSticker array to store our stickers and a function to load them from the local storage.
Written by: Davis Allie
If you feel useful for you and for everyone, please support and follow us.
Suggest for you:








No comments:
Post a Comment