【1】.最終實(shí)現(xiàn)的效果圖
13.gif
- 1.首先登錄環(huán)信官網(wǎng)注冊(cè)即時(shí)通訊云
屏幕快照 2016-11-10 上午11.03.46.png
屏幕快照 2016-11-10 上午11.24.30.png
屏幕快照 2016-11-10 上午11.29.02.png
注冊(cè)成功拿到最終的APPKey.
-
2.在官網(wǎng)下載最新的SDK
屏幕快照 2016-11-10 上午10.53.47.png
下載后的文件包含:
屏幕快照 2016-11-10 上午10.53.13.png
- 3.創(chuàng)建新的工程將HyphenateSDK導(dǎo)入工程
屏幕快照 2016-11-10 下午2.00.26.png
-
4.導(dǎo)入對(duì)應(yīng)的依賴庫(kù)
屏幕快照 2016-11-10 上午11.06.52.png 5.Build Settings 搜索other linke 雙擊添加-ObjC[注意大小寫]
6.配置plist 文檔
0068icBpgw1f8xmrfvt9qj30mb0acadw.jpg
-7. 把bitcode設(shè)置成NO,因?yàn)榄h(huán)信SDK不支持,如下:
1025776-1dd69d5dd8207447.png
配置完成
-8.在AppDelegate中添加代碼
#import "AppDelegate.h"
#import "EMSDK.h"
#import "EaseUI.h"
#import "ChatViewController.h"
#define LZChatAppkey @ "你注冊(cè)時(shí)候的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;
}
運(yùn)行出現(xiàn)登陸成功,Username 和password是你事先注冊(cè)好的。
- 9.導(dǎo)入EaseUI
屏幕快照 2016-11-10 上午11.53.04.png
-10.導(dǎo)入EaseUI運(yùn)行會(huì)報(bào)錯(cuò),需要添加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.工程里面創(chuàng)建一個(gè)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;
}
完成,簡(jiǎn)單的單聊幾面。