【1】.最终实现的效果图

- 1.首先登录环信官网注册即时通讯云



注册成功拿到最终的APPKey.
-
2.在官网下载最新的SDK
屏幕快照 2016-11-10 上午10.53.47.png
下载后的文件包含:

- 3.创建新的工程将HyphenateSDK导入工程

-
4.导入对应的依赖库
屏幕快照 2016-11-10 上午11.06.52.png
-
5.Build Settings 搜索other linke 双击添加-ObjC[注意大小写]
-
6.配置plist 文档

-7. 把bitcode设置成NO,因为环信SDK不支持,如下:

配置完成
-8.在AppDelegate中添加代码
#import "AppDelegate.h"
#import "EMSDK.h"
#import "EaseUI.h"
#import "ChatViewController.h"
#define LZChatAppkey @ "你注册时候的APPKey"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
EMOptions *options = [EMOptions optionsWithAppkey:LZChatAppkey];
options.apnsCertName = @"istore_dev";
[[EMClient sharedClient] initializeSDKWithOptions:options];
EMError *error = [[EMClient sharedClient] loginWithUsername:@"lz" password:@"123456"];
if (!error) {
NSLog(@"登录成功");
}
return YES;
}
运行出现登陆成功,Username 和password是你事先注册好的。
- 9.导入EaseUI

-10.导入EaseUI运行会报错,需要添加PCH文件
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
#endif /* PrefixHeader_pch */
#ifdef __OBJC__
#import "EaseUI.h"
#define NSEaseLocalizedString(key, comment) [[NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"EaseUIResource" withExtension:@"bundle"]] localizedStringForKey:(key) value:@"" table:nil]
#endif
-11.工程里面创建一个Viewcolltroller 继承于EaseMessageViewController
-12.在AppDelegate中添加代码
#import "AppDelegate.h"
#import "EMSDK.h"
#import "EaseUI.h"
#import "ChatViewController.h"
#define LZChatAppkey @ "1142161018115930#lzchat"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
EMOptions *options = [EMOptions optionsWithAppkey:LZChatAppkey];
options.apnsCertName = @"istore_dev";
[[EMClient sharedClient] initializeSDKWithOptions:options];
EMError *error = [[EMClient sharedClient] loginWithUsername:@"lz" password:@"123456"];
if (!error) {
NSLog(@"登录成功");
}
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
ChatViewController *VC=[[ChatViewController alloc]initWithConversationChatter:@"wx" conversationType:EMConversationTypeChat];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:VC];
self.window.rootViewController=nav;
[self.window makeKeyAndVisible];
return YES;
}
完成,简单的单聊几面。
网友评论