[IOS] using imessage in IOS10

Source: Internet
Author: User

This article reprinted to Http://www.tuicool.com/articles/zIFvQn7 Original http://www.bourbonz.cn/using imessage/theme in Ios10iOS DevelopmentUsing Imessage2016-06-22imessage in IOS10

There are two new ways to imessage in iOS, 1. Built-in Emoji pack, 2.iMessage app

1. Built-in Emoticons pack (sticker Packs)

You can create it by creating a new sticker Pack application in Xcode. This way, you can simply add an emoticon to the imessage by adding a picture. Added stickers need to meet the conditions

    1. The image type must be png, apng, GIF, or JPEG
    2. File size must be less than 500K
    3. The image size must be between 100 and 206 206

It is important to note that @3x -sized images (i.e., 300 to 618 618 ) must always be available. The system can automatically adjust the image according to the current device through the runtime to render @2x and @1x

The system is able to adapt the display sticker, so in order to better display the sticker, the best available sticker is the following three types of size

    1. Small 100*100
    2. Medium 136*136
    3. Large 206*206

Adding a method is also very simple, the way directly like

2.iMessage applications

The IMessage app interacts with the full framework and message app. Use the IMessage app to

    1. Renders a custom user interface within the messaging app. Using Msmessagesappviewcontroller
    2. Create a custom or dynamic emoticon package browser. Using Msstickerbrowserviewcontroller
    3. Add text, emoticons, or media files to the text input box of the message app. Using msconversation
    4. Create a message with a specific app data interaction. Using msmessage
    5. Update messages that can affect each other (for example, creating a game or an app that you can work with). Using mssession

We can do the above five things through imessage, the following respectively:

    1. After creating a new blank app, there will be a messagesviewcontroller, inherited from Msmessagesappviewcontroller, this is the homepage where we see AH, the creation of custom interface here.

      And there are several ways

  //is called when the extension is never active into the active state, which occurs when the UI is rendered. Use this method to configure the state before expansion and recovery. -(void) willresignactivewithconversation: (msconversation *) conversation //is called when the extension is moved from active to inactive. This can happen when the interface disappears, changes the session, or exits the message app. Use this method to free up shared resources, store user data, log off the timer, and save enough state information to restore your extended status when it crashes.-(void) Didbecomeactivewithconversation: (msconversation *) conversation      
  //this method is called when it receives a message sent from the other side and is sent through this extension. Use this method to trigger a UI update to correspond to this message.-(void) didreceivemessage: (msmessage *) message conversation: ( Msconversation *) conversation //is called when the Send button is clicked-(void) Didstartsendingmessage: (msmessage *) message conversation: (Msconversation *) conversation // Called when the user deletes the message without sending it. Use this method to clean up the associated delete message state. -(void) didcancelsendingmessage: (msmessage *) message conversation: (Msconversation *) Conversation        
//在拓展从一个过渡到一个新的外观状态前会被调用.使用这个方法来为改变外观状态做准备-(void)willTransitionToPresentationStyle:(MSMessagesAppPresentationStyle)presentationStyle //在拓展已经过度到新的外观状态后会被调用。使用这个方法来完成与外观风格变化有关的任何行为.-(void)didTransitionToPresentationStyle:(MSMessagesAppPresentationStyle)presentationStyle 
    1. Msstickerbrowserviewcontroller drag Add, Long press Preview, click Add. Using this class to customize the expression browser, the customization will be higher, she can change the data dynamically according to data source, you can also customize the size of each sticker. After creating it, you need to implement two proxies Numberofstickersinstickerbrowserview: and Stickerbrowserview:stickeratindex: to return the appropriate content.

      It should be noted that 1. Content if local picture 2. The size of the expression can be adjusted, but still only support is three styles

    2. Msconversation

      If you want to send additional content, you can use Msconversation to do so.

      The current messagesviewcontroller contains a current conversation->activeconversation

You can send a message by using the following methods

//文件-insertAttachment:withAlternateFilename:completionHandler://消息-insertMessage:localizedChangeDescription:completionHandler://表情-insertSticker:completionHandler://文本-insetText:completionHandler:

These methods are called when the corresponding content is sent, it is important to note that this is not to send a message, but to add the message to the text box, the user also need to click the Send button to send.

In addition to the text and stickers, but also the Msmessage object, he can contain unique data, hold a session, let participants update the message, but the rendering of this object requires the Layout property.

There is a URL attribute that requires an HTTP (S) link or a data URL. If a valid link, if it is a URL, then it will be loaded in the browser.

The layout property must be Msmesstemplatelay, and you cannot create subclasses or new msmessagelayout. Message templates contain message extensions for icons, images, video or audio files, as well as some text elements (title, subtitle, title, subcaption, trailing title, and trailing subcaption). Such as

Note that the content sent must be local content, and the Msmessagetemplayout Mediafileurl property is ignored after the Image property is set.

Selectedmessage

To achieve a special interaction, you need to handle the Click event in addition to the send type, which is a msmessage message.

*. If the user clicks on one of the extension messages, the property is set to the current message, otherwise it will be set to nil.

*. If your expansion is initiated by a user clicking on a message, then this property will be set to expand the message at startup. Can listen in didbecomeactivewithconversation .

*. If a user clicks on a message while your extension is running, the value of this property will change. Can listen in willtransitiontopresentationstyle .

*. The page uses KVO to listen for this property in response to the corresponding change. (Actually, honestly, I didn't get it.)

The applied data can be parsed in the URL property of the message.

If the message is associated with a conversation, you can use a new message with a session strength to update the message. Use Conversation's InsertMessage:localizedChangeDescription:completionHandler: method to send a new message. When a user sends a message, the system moves it to the bottom and updates its contents.

You can also save the content.

And finally, my demo. Maybe a little messy.

Point me to jump

[IOS] using imessage in IOS10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.