Creating iMessage Apps with XCode 8
This is part of a series of tutorials introducing new features in iOS 10, the Swift programming language, and the new XCode 8 beta, which were just announced at WWDC 16
Intro
Among the most exciting additions in iOS 10 are some of the new app extension types, and the new extension type that really caught my attention was the iMessage app, which allow you to add functionality to the built-in Messages app on iOS.
Unlike other extension types, which requires you to bundle your extension with a standard app, iMessage apps can be released as standalone apps through the the new iMessage App Store, which will be accessible from within the Messages app. While you can include your Messages app extension as part of a standalone app, with this new branch of the app store, for the first time, you don’t have to.
When users use your iMessage app to communicate with people who don’t have it, the recipient will be prompted with a link to download it from the store.
The purpose of this tutorial is to create a quick, searchable guide for creating a sticker app (which you can do without writing a line of code), and very briefly introduce the new Messages framework (Messages.framework) for building interactive apps.
Creating Content and Apps for iMessage
iMessage Sticker Apps
There’s a very easy option for artists (even non-programmers) who want to release content for the iMessage app store. You can offer sticker apps: purchasable packs of stickers (even animated stickers) that users can “peel” (using a long press) and slap onto any balloon in a conversation. Like all iMessage apps, these packs can be a bonus bundled with your existing app, or a standalone package offered for sale. Apart from creating the assets, releasing a sticker app couldn’t be much easier.
A sticker pane, with a sick computer stuck onto a message
The sticker packs themselves don’t require any code to create. All you really need is a copy of XCode 8 and an Apple Developer account. The few simple guidelines for creating the assets can be found under “Sticker Packs” in the Messages Framework reference. For convenience, I’ve copied a slightly-edited version here.
Each sticker image should meet this criteria:
- The image must be a PNG, APNG, GIF or JPEG file.
- The file must be less than 500KB.
- The image must be between 100×100 and 206×206 points
PNG or APNG (Animated PNG) will generally look best. Make sure your stickers look good against different color backgrounds; they can be applied to photos.
Apple uses points (rather than pixels) for screen coordinates and dimensions on their devices. 10×10 points (pt) @ 2x equals 20×20 pixels (px). The original retina display crammed 4 pixels into the space of one (1×1 became 2×2). Simply by providing ‘@2x’ copies of images at that higher resolution, developers were able to quickly update their old apps to support the sharper display.
Always provide @3x images – between 300×300 and 618×618 pixels. The system generates the @2x and @1x versions by downscaling the @3x images at runtime.
In Xcode’s Attributes inspector, set the Sticker Size for the entire Sticker pack. The system lays out the stickers in the browser based on these sizes. To best match the browser, use sticker images of the specified size. The Sticker Size defaults to Medium.
The recommended maximum dimensions for each size setting are:
- Small: 100x100pts.
- Medium: 136x136pts.
- Large: 206x206pts.
Xcode’s Attributes Inspector after selecting the “Sticker Pack” group in Stickers.xcstickers
Building the App
Start a new project in XCode, and you’ll see there’s a new template for creating a standalone sticker pack.
You’re almost done. Select Stickers.xcstickers and add some icons so that your sticker pack looks good in Messages and on the store, then drag your stickers into the “Sticker Pack” group.
Note: You can create animated (APNG) stickers with just XCode. Right click inside your sticker pack group and select Add Assets -> New Sticker Sequence. Use the attributes inspector on the right to set options like number of frames, framerate and repetition count.
Note: If the app won’t run, try the following:
- Select your “Run” build scheme, ensure that ‘Executable’ is set to [projectname].app (stickers.app in my case)
- Provide images for at least the 1x versions of the 27×20, 32×24, and 1024×768 point icons, as well as the 2x icon for “Settings” and “Messages” for your target platform
- Note that 2x means to double the requested dimensions (2x for 29x29pt means provide a 58×58 px image)
If you are ramping up to release your app, make sure to provide images for all icon versions and sizes.
The new version of the simulator for iOS 10 includes a special version of the Messages app which allows you to see both sides of a conversation as you test your iMessage apps.
My sticker app (containing an animated gif and the obligatory cat photo) may not win any awards, but it works. Here is is in action, with the sticker tray open and a few stickers strategically applied:
If you’ve made it this far (and provided more/better art) your app is now ready for submission to iTunes Connect and Apple’s review process (pending availability of the release version of XCode 8).
Customizing the Sticker Browser
Developers should be aware that it is possible to customize the appearance of the sticker browser (the window that users peel stickers from) in a full-fledged iMessage app by subclassing MSStickerBrowserViewController. You can also load stickers dynamically by setting your StickerBrowserViewController’s data source to a class which conforms to MSStickerBrowserViewDataSource.
Developing Interactive iMessage Apps
There’s a lot more you can do with iMessage Apps. For now, I just want to briefly discuss Messages.framework. I hope to dive much deeper in the near future.
Note: There is one major limitation that may kill your idea. You won’t be allowed to read the content of user’s messages or even, necessarily, know anything about the participants in the session. Apple takes privacy very seriously; this is as it should be.
A number of the built-in apps provide good examples. Apart from the sticker features, the new drawing capabilities, the music sharing app and the Bing image search, in particular, are good examples of the type of thing that third-party developers could realistically build today.
There is a new, relatively bare-bones, project template in XCode 8: “Messages Application”. MessagesViewController a subclass of MSMessagesAppViewController is your main entry point and does at least provide a number of comments. This is the view controller behind your app’s view in the app drawer and when expanded.
The documentation on these classes is there for anyone getting started and a helpful introduction and associated sample project are now available.
I have my stickers ready. How do I push this Apple?
Hey, all the instructions you need are in the article. Read from ‘building the app’.
Thanks, well when I’m in iTunes connect do I just setup my certificates and bundle Id the exact same way I would a normal app? Right Now I get a bunch of errors stating I’m using a non public api when I try to push to Apple.
It’s not yet possible. This StackOverflow question details a similar situation: http://stackoverflow.com/questions/28443583/submitting-ios-app-using-beta-version-of-xcode. Apple will announce when iOS 10, XCode 8, etc. are coming out of beta, and those errors should clear up then (after you download and build your app with the official release).
Thanks for this Jason…so helpful. Is it now possible to build an experience whereby an imessage app could provide additional emoticons (as opposed to stickers)?
Not exactly.
Emoji are actually just sent as unicode characters. We had some space left over in the character set, and the industry got together and agreed that from now on, U+1F3E5 meant hospital, U+1F4A9 meant poop, etc. So when you send an emoji, you’re not sending a little picture, you’re sending a character that the other person’s phone or web browser renders as an image (which it already has). Much less bandwidth. That’s why they look different on different devices and appear as  or □ or similar when passed through something that doesn’t support them.
If they don’t already have it, you can’t send it as an emoji.
Stickers seem like the way to sort of fake what you’re asking for. You can include them as part of a normal message, BTW, you don’t have to peel and stick them, and I’m updating the tutorial to point out that the dimensions I mentioned are the recommended MAXIMUM size for your stickers. I’m not sure if creating ones as small as 🙂 would make for a good user experience, but you could try it.
Here’s a list if you’re curious: http://apps.timwhitlock.info/emoji/tables/unicode
That was fun 🙂
Do you know how to make sticker a uniform size on all devices. I can’t get the sticker to be same size on iPhone plus and iPhone regular
how can we open other app using imessage app ? any sample ? or guidence