ImageVerifierCode 换一换
格式:DOCX , 页数:23 ,大小:22.72KB ,
资源ID:7302374      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7302374.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(集成环信的即时通讯.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

集成环信的即时通讯.docx

1、集成环信的即时通讯集成环信的即时通讯 集成环信的即时通讯字数4007阅读4086评论19喜欢54 收藏文章 分享 现在即时通讯比较火,很多公司会用到即时通讯,所以今天给大家讲讲即时通讯,因为没有服务器,所以使用了环信的SDK写了个即时通讯的demo,由于界面比较多,我不会像之前一样直接上代码,而是手把手一点点给大家说,用最简单的代码完成基本的即时通讯功能,尽量使大家看了这篇博客后都能写出一个简单的即时通讯的demo.github地址上官网注册账号首先来到环信的官网,然后登陆.没有账号先注册一个.进去之后创建应用,如图创建应用界面点击确定后,来到这个界面,只需要记住应用标示(APPKey)就行,

2、待会儿会在代码里用到它.屏幕快照 2016-01-04 下午7.18.38.png然后用cocoapods导入环信SDK,大家可以通过这篇博客来安装cocoapods.创建项目打开终端,输入cd,然后将项目入进去回车,就跳到项目地址,输入命令:pod init,然后会生成一个Podfile,双击这个文件,将里面的东西全删了,然后输入:pod EaseMobSDK,然后在终端输入命令:pod install(如果不行可以试试:pod install -verbose -no-repo-update).接下来就等着SDK下载安装到项目里了,大概几分钟后就好了.这时候需要双击.xcworkspace

3、的那个文件进去.SDK集成就完成了(不知道为什么官方文档里面写的集成特别复杂,需要导入各种框架,修改很多东西,其实只要终端一条指令就OK了).AppDelegate大家还记得刚才的APPKey吧,在AppDelegate里面需要注册使用.#import AppDelegate.h#import ViewController.h#import interface AppDelegate ()endimplementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOpti

4、ons:(NSDictionary *)launchOptions _window = UIWindow allocinitWithFrame:UIScreen mainScreen.bounds; _window.backgroundColor = UIColor whiteColor; _window makeKeyAndVisible; UINavigationController *nav = UINavigationController allocinitWithRootViewController:ViewController allocinit; _window.rootView

5、Controller = nav; /注册环信 EaseMob sharedInstanceregisterSDKWithAppKey:xmh123#cdxmh apnsCertName:; return YES;- (void)applicationWillResignActive:(UIApplication *)application / Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interr

6、uptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. / Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.- (vo

7、id)applicationDidEnterBackground:(UIApplication *)application EaseMob sharedInstance applicationDidEnterBackground:application;- (void)applicationWillEnterForeground:(UIApplication *)application EaseMob sharedInstance applicationWillEnterForeground:application;- (void)applicationDidBecomeActive:(UIA

8、pplication *)application / Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.- (void)applicationWillTerminate:(UIApplication *)application EaseMob sharedInstanceapplic

9、ationWillTerminate:application;end登陆界面登陆界面看看这部分的代码吧.#import ViewController.h#import RegisterViewController.h#import FriendListViewController.h#import interface ViewController ()property(nonatomic, strong)UITextField *userNameTextField;/用户名property(nonatomic, strong)UITextField *passwordTextField;/密码

10、property(nonatomic, strong)UIButton *loginButton; /登陆按钮property(nonatomic, strong)UIButton *registerButton; /注册按钮endimplementation ViewController- (void)viewDidLoad super viewDidLoad; self.view.backgroundColor = UIColor whiteColor; self.navigationController.navigationBar.translucent = NO; self.title

11、 = 登陆界面; UILabel *usernameLabel = UILabel allocinitWithFrame:CGRectMake(20, 100, 80, 50); usernameLabel.text = 用户名; usernameLabel.font = UIFont systemFontOfSize:25; self.view addSubview:usernameLabel; _userNameTextField = UITextField allocinitWithFrame:CGRectMake(usernameLabel.frame.origin.x + usern

12、ameLabel.frame.size.width + 10, usernameLabel.frame.origin.y, 250, 50); _userNameTextField.borderStyle = 3; _userNameTextField.placeholder = 请输入用户名; self.view addSubview:_userNameTextField; UILabel *passwordLabel = UILabel allocinitWithFrame:CGRectMake(usernameLabel.frame.origin.x, usernameLabel.fra

13、me.origin.y + usernameLabel.frame.size.height + 10, usernameLabel.frame.size.width, usernameLabel.frame.size.height); passwordLabel.text = 密码; passwordLabel.font = UIFont systemFontOfSize:25; self.view addSubview:passwordLabel; _passwordTextField = UITextField allocinitWithFrame:CGRectMake(_userName

14、TextField.frame.origin.x, passwordLabel.frame.origin.y, _userNameTextField.frame.size.width, _userNameTextField.frame.size.height); _passwordTextField.placeholder = 请输入密码; _passwordTextField.borderStyle = 3; self.view addSubview:_passwordTextField; _loginButton = UIButton buttonWithType:UIButtonType

15、System; _loginButton.frame = CGRectMake(170, 300, 50, 50); _loginButton.titleLabel.font = UIFont systemFontOfSize:25; _loginButton setTitle:登陆 forState:UIControlStateNormal; _loginButton addTarget:self action:selector(didClickLoginButton) forControlEvents:UIControlEventTouchUpInside; self.view addSu

16、bview:_loginButton; _registerButton = UIButton buttonWithType:UIButtonTypeSystem; _registerButton.frame = CGRectMake(170, 410, 50, 50); _registerButton.titleLabel.font = UIFont systemFontOfSize:25; _registerButton setTitle:注册 forState:UIControlStateNormal; _registerButton addTarget:self action:selec

17、tor(jumpToRegister) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:_registerButton;-(void)didClickLoginButton EaseMob sharedInstance.chatManager asyncLoginWithUsername:_userNameTextField.text password:_passwordTextField.text completion:(NSDictionary *loginInfo, EMError *error) if

18、 (!error) /如果验证用户名和密码没有问题就跳转到好友列表界面 self.navigationController pushViewController:FriendListViewController allocinit animated:YES; else / 显示错误信息的警告 NSLog(%,error); onQueue:dispatch_get_main_queue();-(void)jumpToRegister/跳转到注册界面 RegisterViewController *registerVC = RegisterViewController allocinit; se

19、lf.navigationController presentViewController:registerVC animated:YES completion:nil;- (void)didReceiveMemoryWarning super didReceiveMemoryWarning; / Dispose of any resources that can be recreated.end这个界面很简单,大部分都是界面搭建,当点击登陆时会调用EaseMob sharedInstance.chatManager asyncLoginWithUsername:_userNameTextFi

20、eld.text password:_passwordTextField.text completion:(NSDictionary *loginInfo, EMError *error)这个方法有2个参数,一个用户名,一个是密码,很容易猜到这就是验证你的用户名和密码是否正确,如果正确就跳转到好友列表界面,如果不对就会在控制台打印相应的错误.点击注册就跳转到注册界面.注册界面注册界面由于第一次登陆时没有账号,所以先得注册.先看看代码:#import RegisterViewController.h#import interface RegisterViewController ()proper

21、ty(nonatomic, strong)UITextField *userNameTextField;/用户名property(nonatomic, strong)UITextField *passwordTextField;/密码property(nonatomic, strong)UIButton *registerButton; /注册按钮endimplementation RegisterViewController- (void)viewDidLoad super viewDidLoad; self.view.backgroundColor = UIColor whiteColor

22、; self.navigationController.navigationBar.translucent = NO; self.title = 登陆界面; UILabel *usernameLabel = UILabel allocinitWithFrame:CGRectMake(20, 100, 80, 50); usernameLabel.text = 用户名; usernameLabel.font = UIFont systemFontOfSize:25; self.view addSubview:usernameLabel; _userNameTextField = UITextFi

23、eld allocinitWithFrame:CGRectMake(usernameLabel.frame.origin.x + usernameLabel.frame.size.width + 10, usernameLabel.frame.origin.y, 250, 50); _userNameTextField.borderStyle = 3; _userNameTextField.placeholder = 请输入用户名; self.view addSubview:_userNameTextField; UILabel *passwordLabel = UILabel allocin

24、itWithFrame:CGRectMake(usernameLabel.frame.origin.x, usernameLabel.frame.origin.y + usernameLabel.frame.size.height + 10, usernameLabel.frame.size.width, usernameLabel.frame.size.height); passwordLabel.text = 密码; passwordLabel.font = UIFont systemFontOfSize:25; self.view addSubview:passwordLabel; _p

25、asswordTextField = UITextField allocinitWithFrame:CGRectMake(_userNameTextField.frame.origin.x, passwordLabel.frame.origin.y, _userNameTextField.frame.size.width, _userNameTextField.frame.size.height); _passwordTextField.placeholder = 请输入密码; _passwordTextField.borderStyle = 3; self.view addSubview:_

26、passwordTextField; _registerButton = UIButton buttonWithType:UIButtonTypeSystem; _registerButton.frame = CGRectMake(170, 330, 50, 50); _registerButton.titleLabel.font = UIFont systemFontOfSize:25; _registerButton setTitle:注册 forState:UIControlStateNormal; _registerButton addTarget:self action:select

27、or(didClickedRegisterButton:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:_registerButton; UIButton *backButton = UIButton buttonWithType:UIButtonTypeSystem; backButton.frame = CGRectMake(170, 280, 50, 50); backButton.titleLabel.font = UIFont systemFontOfSize:25; backButton se

28、tTitle:返回 forState:UIControlStateNormal; backButton addTarget:self action:selector(backAction) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:backButton;-(void)backAction self dismissViewControllerAnimated:YES completion:nil;-(void)touchesBegan:(NSSetUITouch * *)touches withEvent

29、:(UIEvent *)event/点击屏幕时让键盘回收 _passwordTextField resignFirstResponder; _userNameTextField resignFirstResponder;-(void)didClickedRegisterButton:(id)sender/ 登陆和注册有3种方法: 1. 同步方法 2. 通过delegate回调的异步方法。3.block异步方法 /其中官方推荐使用block异步方法,所以我这里就用block异步方法 /开始注册 EaseMob sharedInstance.chatManager asyncRegisterNew

30、Account:_userNameTextField.text password:_passwordTextField.text withCompletion:(NSString *username, NSString *password, EMError *error) if (!error) NSLog(注册成功); self dismissViewControllerAnimated:YES completion:nil; else NSLog(%,error); onQueue:dispatch_get_main_queue();- (void)didReceiveMemoryWarning super didReceiveMemoryWarning; / Dispose of any resources that can be recreated./*#pragma mark - Navigation/ In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1