I believe you will use instant messaging function in the project. If you write on your own, you will need front-end and back-end cooperation, which will greatly increase the development cycle, so consider using third-party instant messaging platforms, such as Messenger Cloud, Messenger.... Etc. now! The landlord has used Messenger and Messenger Cloud in the project development process. Today, write down the methods and possible encounters of integrating Messenger on IOS side for you.Question.(Melt Cloud offers chat session lists and chat interfaces and allows us to customize them, so it's convenient).
I: Preparations
1. First open Rongyun Official Website http://www.rongcloud.cn/, register your account and log in.
2. Click on the left to create an app and fill in some information about your project in a small window that opens (if you are in the development stage, you can choose a non-operational user, if you need to submit an application for review when the project comes online, then come back later).
3. If there is no higher customization requirement for the interface and all the chat and other interfaces provided by Melting Cloud itself are sufficient, then the IMKit framework can be integrated, and CocoaPods is recommended for automatic integration.
3. Integration
(1) Generate Podfile files, select IM framework
platform :ios, '8.0'target 'RongCloudKit' do pod 'RongCloudIM/IMLib', '2.8.0' //You need to customize the UI interface yourself pod 'RongCloudIM/IMKit', '2.8.0' //Cloud melting provides a complete UI interface end
(
2) Import the header file after installation to use
4. Use (RCIM is a singleton class by which almost all important operations are performed)
(1) Register Cloud Melting APPKey
//Register Cloud Fusion APPKEY[[RCIM sharedRCIM] initWithAppKey:APPKEY];
(2) Log on to the cloud-melting server
//Log in using a manually generated token to connect to a cloud-melting server [[RCIM sharedRCIM] connectWithToken:TOKEN success:^(NSString *userId) { NSLog(@"Landing was successful.Currently logged on user ID: %@", userId); } error:^(RCConnectErrorCode status) { NSLog(@"The error code for landing is:%ld", status); } tokenIncorrect:^{ //Token is out of date or incorrect.//If token expiration is set and token expires, re-request your server to get a new token. //If token expiration is not set but token error is prompted, check that your client and server appkey s match, and check the process by which you get token. NSLog(@"token error"); }];
(3) Show the chat interface code as follows (here I inherit the native session class RCConversationViewController)
// RongCloudConversationViewController.h// RongCloudKit/// Created by Summer Yuanquan on 16/12/17. // Copyright 2016 Guangzhou East Germany Network Technology Co., Ltd. All rights reserved. /#import <RongIMKit/RongIMKit.h>@interface SystemConversationViewController: RCConvoller@end
// RongCloudConversationViewController.m// RongCloudKit/// Created by Xia Yuanquan on 16/12/17. // Copyright 2016 Guangzhou East Germany Network Technology Co., Ltd. All rights reserved. /#import "SystemConversationViewController.h"@interface SystemConversationViewController ()<RCIMUserInfoDataSource>@end@implementation SystemConversationViewControllerNViewController-(instancetype)init{ self = [super init]; //Set the type of session, such as single chat, discussion group, group chat, chat room, customer service, public service session, etc. self.conversationType = ConversationType_PRIVATE; //Sets the target session ID for the session.(Single chat, customer service, public service session is the ID of the other party, discussion group, group chat, chat room is the ID of the session) self.targetId = OTHERID; //Set the title to be displayed in the chat session interface self.title = OTHERID; return self; }-(void)viewDidLoad{ [super viewDidLoad]; //User Information Provider [RCIM sharedRCIM].userInfoDataSource = self; }#pragma mark - <RCIMUserInfoDataSource>/*! Get user information @param userId User ID @param completion Block [userInfo: User information for the user ID] that needs to be executed after getting user information is complete @discussion SDK Use this method to get user information and display it. Return the user information corresponding to the user ID in completion. Once you have set up a user information provider, the SDK calls this method when it needs to display user information and requests that user information be used for display. */-(void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion { //Set User Information NSString *avatarURL = @"http://xxxxxx.com/static/avatar/137180371639017.jpeg"; RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:userId name:userId portrait:avatarURL]; //block callback to set user information completion(userInfo); }@end
//Chat interface - (void)conversationStart{ //Create a new chat session View Controller object and display the chat session interface SystemConversationViewController *chat = [[SystemConversationViewController alloc]init]; [self.navigationController pushViewController:chat animated:YES]; }
(4) The display session list interface code is as follows (here I inherit the native session list class RCConversationListViewController)
// ConversationListViewController.h// RongCloudKit/// Created by Summer Yuanquan on 16/12/17. // Copyright 2016 Guangzhou East Germany Network Technology Co., Ltd. All rights reserved. /#import <RongIMKit/RongIMKit.h>@interface SystemConversationListViewoller: RCConversationListController@end
// ConversationListViewController.m// RongCloudKit/// Created by Summer Yuanquan on 16/12/17. // Copyright 2016 Guangzhou East Germany Network Technology Co., Ltd. All rights reserved. //#import "SystemConversationListViewController.h"#import "SystemConversationViewController.h"@interface SystemConversationViewController ()<RCIMUserInfoDAtaSource>@end@implementation SystemConversationListViewController- (void) viewDidLoad { //To override the display-related interface, you must call super first, otherwise the SDK default processing will be blocked [super viewDidLoad]; self.conversationListTableView.tableFooterView = [[UIView alloc] init]; //Set which types of sessions need to be displayed [self setDisplayConversationTypes:@[@(ConversationType_PRIVATE), @(ConversationType_DISCUSSION), @(ConversationType_CHATROOM), @(ConversationType_GROUP), @(ConversationType_APPSERVICE), @(ConversationType_SYSTEM)]]; //Set which types of sessions need to be aggregated in the session list to display [self setCollectionConversationType:@[@(ConversationType_DISCUSSION), @(ConversationType_GROUP)]]; //User Information Provider [RCIM sharedRCIM].userInfoDataSource = self; }//Override the onSelectedTableRow event for RCConversationListViewController - (void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath { SystemConversationViewController *conversationVC = [[SystemConversationViewController alloc]init]; conversationVC.conversationType = model.conversationType; conversationVC.targetId = model.targetId; conversationVC.title = model.targetId; [self.navigationController pushViewController:conversationVC animated:YES]; }#pragma mark - <RCIMUserInfoDataSource>/*! Get user information @param userId User ID @param completion Block [userInfo: User information for the user ID] that needs to be executed after getting user information is complete @discussion SDK Use this method to get user information and display it. Return the user information corresponding to the user ID in completion. Once you have set up a user information provider, the SDK calls this method when it needs to display user information and requests that user information be used for display. */-(void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion { //Set User Information NSString *avatarURL = @"http://xxxxxx.com/static/avatar/137180371639017.jpeg"; RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:userId name:userId portrait:avatarURL]; //block callback to set user information completion(userInfo); }@end
//Session List - (void)chatViewList { //Create a new session list interface class to display all session contacts SystemConversationListViewController *chatList = [[SystemConversationListViewController alloc] init]; [self.navigationController pushViewController:chatList animated:YES]; }
Five, demo screenshots
6. A hint
The development documents of Rong Yun are quite detailed. I'll write here that it's just idle and amusement. If you need to go to the official documents, the details of the documents are really amazing to my brother~~
http://www.rongcloud.cn/docs/