⬆️ ⬇️

iMessage in iOS 10: New Opportunities for Developers





At WWDC 2016, Apple introduced the iMessage update. From the Keynote presentation, it seemed that nothing interesting had happened: stickers, large emojis and animated fireworks were added. But in fact, Apple introduced a whole new platform and opened Messages for developers. This was discussed in detail at the lectures of iMessage Apps and Stickers, Part 1 and Part2 . For those who have not yet had time to look at them, but at least a little interested, the new opportunities for developers will be discussed below.





')

Two new types of applications are available to us:



Both of these types can be created together with an iOS application in the form of an extension, or they can exist independently. In both cases, the application will be available to the user in the Message Store.







IMessage applications, in turn, can provide three types of content:



Available platforms



Applications will be available only on the iOS 10 platform. There you can create and send stickers. You can receive and correctly display messages on macOS Sierra and watchOS 3.0. But on wathOS 3.0, the last used stickers will be available, and they can be sent. In addition, they promise a backward compatibility mechanism, so on iOS 9, instead of an interactive message, 2 messages will arrive, one of which will contain a link to content on the web.



A development project for Android is not foreseen, which makes iMessage somewhat limited.



Simulator and Message Store



Two users are available for testing in the simulator. You can have a dialogue between them. After each launch, the message history is cleared.



Applications can be used from the Application Drawer (it will contain applications created as extension and downloaded from the Message App Store) and from the Message App Store itself. In addition, the Inline App Attribution mechanism will be presented. If the user receives a message created in the application, which he does not need, then the user will see the corresponding signature under the message. When you click on it, the user will go to the store, where they can download the desired application.



It’s impossible to see what the Store is all about so far, either on the simulator or on a device with iOS 10 beta, because it’s not yet running.



Stickers



If you decide to create a set of stickers, then I have good (or not) news for you. You do not need to write a single line of code. Choose the Sticker Pack Application and add your resources there. It is important to understand that this is a static set, and you can only change it by reloading the application.

You can create static and animated stickers.







However, there is a set of resource requirements.
  1. PNG, APNG, GIF or JPEG formats. But from this variety, Apple recommends the PNG and APNG formats, in order to avoid image artifacts.
  2. The file is no more than 500 KB.
  3. The image must be greater than 100 x 100 pixels and less than 206 x 206.


In addition, Apple recommends that the size of the stickers correspond to one of the three options, because the stickers can be placed in any part of the message, but all this is done in accordance with the dimensional grid. Accordingly, if the size of your sticker does not fit this grid, then something can go wrong. The sizes are as follows:

  • Small. 100 x 100 points.
  • Medium. 136 x 136 dots.
  • Large. 206 x 206 dots.


Resources are required at 3x resolution, and the system can reduce them if the need arises.



After everything is ready, you can start the application by selecting Messages as the target application. Our stickers are already in the list of applications, and you can use them.







We obtained a simple result with minimal time costs.



iMessage Apps



It will take much more time to create an iMessage application, but you can also get a more interesting and useful result. Here you need to write code, but in the development you can use all the usual iOS SDK.



In the Apple presentation, as an example, an application was shown that makes ice cream stickers. If you turn the ice cream into a pizza, then even the stickers will be useful from a business point of view.



In addition to stickers, iMessage applications can create interactive messages, and this can be anything. Cards, payment forms, music.



What is an interactive message?

So Apple calls the messages that are created inside extensions, they look like this:







Now consider the structure of the message. It consists of the MSSession, which is responsible for how the message will be sent, and MSMessageTemplateLayout, which is responsible for displaying the message in the conversation. In the standard layout, you can specify image or mediaFileURL (if you want to use video, for example, the content will be in place of the image), and many more caption, which can be seen below on the slide. You can also set the url for the message. This will allow a user with macOS or an earlier version of iOS to interact with the content of the message in a web browser.







Let's consider what parts the application consists of.

The first is MSMessagesAppViewController. This is the controller the user interacts with when he selects your application. He is the heir to the UIViewController. The screen can be in two states: compact and expanded. You can add any ViewController to it as a ChildViewController.







The second is MSConversation. This is a conversation where user IDs are stored and where you can add your messages.







Third, MSMessage. This is an interactive message.







In the simplest version of the extension, you just need to create your MSMessagesAppViewController, on which elements of the collection will be displayed. When you select an item, generate a message and then add it to the conversation. In general, this is the main functionality of the extensions. And already optionally, when selecting a message, you can add actions, open an application, play music, show a new controller.



Total



We found that creating an application is simple, and a set of stickers is even easier. All this gives developers the ability to solve user problems, even if they have only iMessage running.



Links



All the above components are in the Messages framework

Apple Application Code

Source: https://habr.com/ru/post/304486/



All Articles