iOS integrated Cloud SDK Instant Messaging

Source: Internet
Author: User
Tags session id

I believe that everyone in the project will use the Instant Messaging function, to write their own words will need to work together before and after, will greatly increase the development cycle, so consider the use of third-party instant communication platform, such as now have a cloud, ring letter .... Wait, wait! The landlord in the project development process to use the ring letter and cloud, today for everyone to write down the iOS side integrated ring letter method and may encounter problems. (Cloud provides chat session list and chat interface and allows us to customize, so it is convenient).

One: the preparatory work
1. First open the http://www.rongcloud.cn/website, register your account and log in.
2. Click on the left side to create the app, fill in the open window with some information about your project (if you are in the development stage you can choose not to run business users, if the project will need to submit an application review after the launch, later on).

3. If the interface does not have a higher customization requirements, the cloud itself provides all the chat and other interfaces are sufficient to use, when the integration of the Imkit framework can be used, it is recommended to use Cocoapods automatic integration

Third, Integration

(1) Generate Podfile file, select IM framework

Platform:ios, ' 8.0 ' target ' rongcloudkit ' do pod ' rongcloudim/imlib ', ' 2.8.0 '//need to customize the UI interface pod ' Rongcloudim/imkit ', ' 2.8.0 '//Cloud provides a complete UI interface end

2) After installation, the import header file can be used

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/791499/201612/791499-20161218174055183-143801096. PNG "alt=" 791499-20161218174055183-143801096.png "/>

Four, use (Rcim is a singleton class, almost a lot of important operations are done by this class )

(1) Register Cloud Appkey

Registered Cloud APPKEY[[RCIM SHAREDRCIM] Initwithappkey:appkey];

(2) Login to cloud server

650) this.width= 650, "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

//using a manually generated token connection Connect to Cloud Server for login     [[rcim sharedrcim] connectwithtoken:token success:^ (NSString  *userid)  {        nslog (@ "landed successfully. Currently logged in user id:%@ ",  userid);            }  error:^ (Rcconnecterrorcode status)  {        nslog (@ "Login error code is: %ld ",  status);    } tokenincorrect:^{        The  //token is outdated or incorrect.         //If token expiration is set and token expires, please re-request your server for a new token         //If you do not set a token validity period and you are prompted for token errors, check that your client and server Appkey match and check your token acquisition process.         nslog (@ "token error");     }]; 

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

(3) Display the chat interface code as follows (here I inherit the native session class Rcconversationviewcontroller)

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

rongcloudconversationviewcontroller.h//rongcloudkit////Created by Xiahuan on 16/12/17.//Copyright 2016 Guangzhou East Germany Network Technology Limited Company. All rights reserved.//#import <RongIMKit/RongIMKit.h> @interface systemconversationviewcontroller: [Email Protected

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

  rongcloudconversationviewcontroller.m//  rongcloudkit////  created by   Xiahuan  on 16/12/17.//  copyright  2016   Guangzhou East Germany Network Technology Co., Ltd. . all  rights reserved.//#import   "SystemConversationViewController.h" @interface   systemconversationviewcontroller  () <RCIMUserInfoDataSource>@[email protected]  systemconversationviewcontroller-(instancetype) Init{    self = [super init]         //set the type of session, such as single chat, discussion group, group chat, chat room, customer service, public services session      self.conversationtype = conversationtype_private;        // Sets the target session ID for the session. (single chat, customer service, public services session for each other's ID, discussion group, group chat, chat room for the session ID)     self.targetId = OTHERID;         //set the title of the chat session interface to be displayed     self.title = OTHERID;        &nbSp;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   get the block [userinfo you need to perform after the user information is completed: This user ID corresponds to the user information]  @discussion  sdk This method to obtain the user information and display, in completion, return the user information corresponding to that user ID.   After you set up the user information provider, the SDK calls this method when it needs to display user information, asking you to request user information 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 Set User information     completion ( UserInfo);} @end

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

Chat interface-(void) conversationstart{//Create a new Chat session View Controller object, display chat session interface Systemconversationviewcontroller *chat = [[    Systemconversationviewcontroller Alloc]init]; [Self.navigationcontroller pushviewcontroller:chat animated:yes];}

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

(4) Display the session list interface code as follows (here I inherit the native session list class Rcconversationlistviewcontroller)

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

conversationlistviewcontroller.h//rongcloudkit////Created by Xiahuan on 16/12/17.//Copyright 2016 Guangzhou East Germany Network Technology Co., Ltd. All rights reserved.//#import <RongIMKit/RongIMKit.h> @interface systemconversationlistviewcontroller: [Email Protected

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

  ConversationListViewController.m//  RongCloudKit////  Created by  Xiahuan  on 16/12/17.//  copyright  2016   Guangzhou East Germany Network Technology Co., Ltd.  all rights  reserved.//#import   "SystemConversationListViewController.h" #import   " SystemConversationViewController.h "@interface  SystemConversationListViewController  () < rcimuserinfodatasource>@[email protected] systemconversationlistviewcontroller-  (void) viewdidload {        //overrides display related interfaces, you must first call super, otherwise it will mask the default processing of the SDK      [super viewDidLoad];     self.conversationlisttableview.tablefooterview = [[uiview alloc] init];         //sets which types of sessions need to be displayed     [self setdisplayconversationtypes:@[ @ (conversationtype_private), &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp;                            @ (conversationtype_discussion),                                           @ (conversationtype_chatroom),                                          @ (Conversationtype_group),                                          @ ( Conversationtype_appservice),                                          @ (Conversationtype_system)]];        // Sets which types of sessions need to be aggregated in the session list to display     [self setcollectionconversationtype:@[@ (conversationtype_ DISCUSSION),                                            @ (Conversationtype_group)]];             //user information provider &NBSP;&NBSP;&NBSP;&NBSP;[RCIM&NBSP;SHAREDRCIM]. Userinfodatasource = self;} Override Rcconversationlistviewcontroller's Onselectedtablerow event-  (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   get the block [userinfo you need to perform after the user information is completed: The user ID corresponds to theUser Information]  @discussion  sdk This method to obtain user information and display it, return the user information corresponding to that user ID in completion.   After you set up the user information provider, the SDK calls this method when it needs to display user information, asking you to request user information 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 Set User information     completion (userInfo);} @end

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>

Session List-(void) chatviewlist{//Create a new Session List interface class that displays all session contacts Systemconversationlistviewcontroller *chatlist = [[Systemcon    Versationlistviewcontroller alloc] init]; [Self.navigationcontroller pushviewcontroller:chatlist animated:yes];}

Five, demo

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/9C/D8/wKiom1l27JDC0dkzAAFMuzZCpuQ778.png-wh_500x0-wm_ 3-wmp_4-s_3038853752.png "title=" qq picture 20170725150014.png "alt=" Wkiom1l27jdc0dkzaafmuzzcpuq778.png-wh_50 "/>

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/9C/D8/wKioL1l27K_RZxzhAAHCcKi27u8520.png-wh_500x0-wm_ 3-wmp_4-s_3364657694.png "title=" _20170725150045.png "alt=" Wkiol1l27k_rzxzhaahccki27u8520.png-wh_50 "/>

six, hint

 Cloud Development documentation Some of the very detailed, I write here is purely idle to do nothing, entertain, have this need or to see the official documents, that the details of the document, I am the brother of the taxi ~ ~ ~

http://www.rongcloud.cn/docs/


iOS integrated Cloud SDK Instant Messaging

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.