Many apps now need to integrate IM capabilities, and today we'll share the steps to integrate IM basic functionality. This article takes Jmessage as an example.
Aurora im (jmessage) = Aurora push (Jpush) + IM, this article discusses only the IM part of it, providing a concise example of how quickly you integrate IM functionality.
Let's take a look at the correspondence between the basic functions of IM and the content of this article:
Line 0: Getting Ready for work
- Download SDK
- Integration SDK
Line 1: Introduction of header File
#import <JMessage/JMessage.h>
Jmessage Core header file. This is the only header file that needs to be imported into your project, and it references a header file that needs to be used internally.
Line 2: Turn on event monitoring
[JMessage addDelegate:self withConversation:nil];
- For monitoring various global events
- Suggested before Line 3
- Parameters:
- Delegate: Fill in objects need to implement <JMessageDelegate>
- Conversation:nil monitoring of all notifications, non-nil monitoring of the specified session
Line 3: Launch SDK
[JMessage setupJMessage:launchOptions appKey:@"your appkey" channel:@"channel name" apsForProduction:NO category:nil];
- Suggestions are written
application:didFinishLaunchingWithOptions:
in
- Parameters:
- Launchoptions: parameter of the start function launchingoption
- AppKey: Get Way Line 0-integrated SDK
- Channel: The name of the application
- Isproduction: Whether it is a production mode
- CATEGORY:IOS8 new Notification Shortcut button parameters
Line 4: Register a new user
[JMSGUser registerWithUsername:@"username" password:@"password" completionHandler:^(id resultObject, NSError *error) {}];
Parameters:
- Username: User Name
- Password: password
- Successful call when Handler:error is nil (bottom)
Line 5: Login
[JMSGUser loginWithUsername:@"username" password:@"password" completionHandler:^(id resultObject, NSError *error) {}];
Line 6: Create a single chat session
[JMSGConversation createSingleConversationWithUsername:@"username" completionHandler:^(id resultObject, NSError *error) {}];
- A session is the core of the entire IM, and all message behaviors are based on the "session"
- The session does not exist and will return a Xinhui session, which will return existing sessions
- Parameters:
- Handler: Resultobject is jmsgconversation Session object when normal return
- ((jmsgconversation*) resultobject). Target: The opponent of the session:
- User Object Jmsguser
- Group Object Jmsggroup
- Related APIs:
- Create a single-chat cross-app session
- Create a group chat session
Line 7: Send text message
[(JMSGConversation*)resultObject sendTextMessage:@"text"];
- Transform line 6-handler
resultObject
and send text messages
- Related APIs:
- Send picture message
- Send Voice message
- Send a file message
- Send geo-location messages
Line 8~12: Receiving text messages
- (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{ if (message.content == kJMSGContentTypeText) { NSString *text = ((JMSGTextContent *)message.content).text; }}
- Added the <JMessageDelegate> class to line 2 to listen to this method
- This method is called when the APP receives messages (text, images, etc.)
- by
message.contentType
Judging the message type
- Transform
message.content
to text content and get text text
to show UI
- Related APIs:
- Picture content
- Sound content
- File contents
Line 13: Get historical News
NSArray *messages = [(JMSGConversation*)resultObject messageArrayFromNewestWithOffset:nil limit:nil];
- Use the transformation in line 6 to
resultObject
get
- Single chat group chat can be
- Parameters:
- Back to nsarray<jmsgmessage* >
- Offset: The starting point. Nil starts with the latest article, and N is traced to history from the latest article n
- Limit: quantity. Nil table All
Line 14~15:0 Number of unread messages in a single chat
JMSGConversation *conversation = [JMSGConversation singleConversationWithUsername:username];[conversation clearUnreadCount];
Line 16: Get a list of sessions
[JMSGConversation allConversations:^(id resultObject, NSError *error) {}];
- Bulk Get all Sessions list
- Judging by session type is a single chat or a group chat
- Parameters:
- Resultobject:nsarray<jmsgconversation*>
Line 17: Delete a single chat session
BOOL success = [JMSGConversation deleteSingleConversationWithUsername:username];
- Related APIs:
- Delete a single chat cross app session
- Delete a group chat session
Line 18: Get user details in bulk
[JMSGUser userInfoArrayWithUsernameArray:nameArr completionHandler:^(id resultObject, NSError *error) {}];
- Parameters:
- Namearray:nsarray<nsstring*>
- Resultobject:nsarray<jmsguser*>
- Related APIs:
- Get the details of this user
- Modify this user details
- Modify this user password
Line 19: Create groups and related actions
[JMSGGroup createGroupWithName:name desc:desc memberArray:members completionHandler:^(id resultObject, NSError *error) {}];
- Parameters:
- Name: Group name
- Desc: Group Description
- Memberarray: Member List,nsarray<nsstring*>
- Resultobject: Group Object Jmsggroup
- Related APIs:
- Get a list of my groups
- Get a list of group members
- Add Member
- Delete Member
- Retreat Group
- Get group Details
- Modify group Details
Line 20: Sign Out
[JMSGUser logout:^(id resultObject, NSError *error) {}];
At this point an IM all the basic operation is over, is it very simple?
Pikacode-Aurora (Jpush for Aurora team account)
Original: 20 lines of code fast APP plus chat function
News column: Aurora Daily
20 lines of code fast APP plus chat function