IOS Integrated Ring Letter (III)

Source: Internet
Author: User

Partially reproduced in the Ring letter website

Integrated SDK Foundation features

This article mainly introduces the functions of ring-letter initialization, registration and landing. Because the Ring letter demo did a good job, but the function is too much, want to extract part of the function from the more difficult, so write this article record the integration of the process of the ring letter.

Easeui User Guide

Easeui encapsulates the commonly used controls for IM functionality, such as chat sessions, session lists, and contact lists, designed to help developers quickly integrate the ring-letter SDK. Easeui inside the code is open source, if we are interested in studying the code of EASEUI, see how they encapsulate the code.

Fast Integration

In our download from the official download of the SDK, there is a folder called Easeui, we can directly drag this folder to our project,:

Drag this easeui into our project and check Copy items if needed this option.

Drag the Easeui resource file EaseUIResource.bundle into our project, easeuiresource.bundle it with the image files needed for the interface. :

At this point, after the integration of Easeui and easeuiresource.bundle, our rapid integration of this link is completed, we can try to compile, command + B compile the project, if follow the above steps, we can compile successfully.

Initializing the Ring Letter SDK

As we use the SDK of other companies, we have to initialize our integrated SDK when we open the application, and the ring-letter SDK is not unexpected.

Adding header files to the PCH

First, we need to create a PCH file in our own project, and then place the header files that are often used in the SDK in the PCH file. For the time being, we need to EaseUI.h import the and SDK into the EMSDKFull.h PCH file. The code looks like this:

#import"This project uses features only available in iOS SDK 3.0 and later."#endif#ifdef __OBJC__#import <UIKit/UIKit.h>#import <Foundation/Foundation.h>#import"EMSDKFull.h"#import"EaseUI.h"1#endif
Initializing the SDK

In the ring chatDemo-UI3.0 , they are putting initialization and push operations AppDelegate + EaseMob in this file, the benefit of which is to simplify the Appdelegate code, because when we do the project, we often want to Appdelegate do a lot of initialization operations, such as Baidu Map SDK initialization, laser push SDK initialization, and so on, if all in this, will cause the code is unusually bloated and difficult to read. Therefore, we also create a new appdelegate category file, which writes the initialization and push code in this category. Some of the code is as follows:

#Import "Appdelegate+easemob.h"#Import "Appdelegate+easemobdebug.h"/** * Easemob initialization and push operations are done in this class */@implementationAppdelegate (Easemob)-(void) Easemobapplication: (UIApplication *) Applicationdidfinishlaunchingwithoptions: (Nsdictionary *) launchOptions Appkey: (NSString *) Appkey apnscertname: (NSString *) apnscertname otherconfig: (nsdictionary *) otherconfig{//Register login status Monitoring[[Nsnotificationcenter Defaultcenter] addobserver:self selector:@selector(Loginstatechange:) name:knotification_loginchange    Object:nil]; [[Easesdkhelper Sharehelper] Easemobapplication:application didfinishlaunchingwithoptions:launchoptio NS Appkey:appkey Apnscertname:apnscertna Me Otherconfig:@{ksdkconfigenableconsolelogger:[nsnumber numberwithbool:yes],@"Easesandbox": [NSNumber numberwithbool:[self Isspecifyserver]}];//[Chatdemohelper sharehelper];BOOL isautologin = [Emclient sharedclient].isautologin;if(Isautologin) {[[Nsnotificationcenter Defaultcenter] Postnotificationname:knotification_loginchange object:@YES]; }Else{[[Nsnotificationcenter Defaultcenter] Postnotificationname:knotification_loginchange object:@NO]; }} #pragma mark-app Delegate//Devicetoken The resulting pass to the SDK- (void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) deviceToken{ Dispatch_async (Dispatch_get_global_queue (Dispatch_queue_priority_default,0), ^{[[Emclient sharedclient] binddevicetoken:devicetoken]; });}//Register Devicetoken failure, here failure, not related to the Ring Letter SDK, is generally your environment configuration or certificate configuration error- (void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) error{ Uialertview *alert = [[Uialertview alloc] Initwithtitle:nslocalizedstring (@"Apns.failtoregisterapns", Fail to register APNs) message:error.description Delegate:nil cancelbuttontitle:nslocalizedstring (@"OK", @"OK") Otherbuttontitles:nil]; [Alert show];}

IOS Integrated Ring Letter (III)

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.