看淘网
当前位置: 首页> 聊天攻略> 在iOS中进行简单的聊天,实现朋友和聊天

在iOS中进行简单的聊天,实现朋友和聊天

发布时间:2019-08-20 21:10:41 作者:xhs
在iOS中进行简单的聊天,实现朋友和聊天:('\n版权声明\n本文首先摘自陈怀哲的《简书》:超链接http://www.jinshu.com/users/9f2e536b78fd/最新文章;\n:陈怀哲(陈怀哲2016);\n未经授权,请重新打印,但请自觉保留上述版权声明。\n\n\n\n\n\n朋友和聊天流程图\n\n阅读本文之前,您需要配置服务器并完成注册和登录的基本功能,然后才能继续您的朋友和聊天。\n以下两篇文章是环境配置和注册和登录功能的详细描述:\nhyperlink xmpp for mysql and openfire environment configuration\nhyperlink ios xmpp simple chat to reach registration and login \nalso must unders还有一些关于coredata的知识,单击“登录”后,成功的验证将跳转到“朋友”页面。现在是时候显示您已经有朋友了。\nso在TableViewCell中要显示您朋友的姓名,您需要一个数据源,数据源从服务器获取该数据源,以查看您是否有朋友,检索您的朋友并将其显示在列表中。\n用于管理朋友的xmpp类是xmpproster,and coredata is used to store friends for data persistence.\nwe can the n encapsulate in xmppmanager the repository where the friends are retrieved and the initialization of the xmpproster object.\n在.h文件中声明:strong)xmpproster*xmpproster;.
\n下面是代理程序:\n
@interface xmppmanager:nsObject.
\nin a.m file to override the init method:\n\n//2.friend management//获取一个coredata仓库,在该仓库中存储用于数据持久性的朋友\nxmpProstoreCataStorage*RosterCoardataStorage=[xmpPosterCredataStorage sharedInstance];\n//初始化xmpPoster\n自身。xmpproster=[[xmpproster alloc]initWithRosterStorage:RosterCoordataStorage DispatchQueue:Dispatch_get_main_queue()];\n//激活\n[自我]。xmppresser activate:self-xmppstream];\n//设置代理服务器\n[self-xmppresser adddelegate:self-delegatequeue:dispatch-get-main-queue()];\n\n\n接收好友请求。\n接收好友请求的方法也封装在xmppmanager中:\n\n//接收好友时执行的方法请求\n-(void)xmppresser:(xmppresser*)发送方未接收到PresenceSubscriptionRequest状态:(xmpppresence*)\n选择。fromjid=存在。发件人;\nIAlertView*Alert=[[UIAlertView alloc]initWithTitle:@“提示:有人添加您的”消息:状态。来自用户委托:self cancelbuttonttitle:@“拒绝”otherbuttonttitles:@“确定”,nil];\n[警报显示];\n \n\n-(void)警报视图:(uialertview*)警报视图clickedbuttonatindex:(nsinteger)buttonindex \n开关(buttonindex)\n可以是0:\n[自我。xmppresser rejectpresencesubscriptionrequestfrom:self-fromjid];\nbreak;\ncase 1:\n[self-xmppresser acceptpresencesubscriptionrequestfrom:self-fromjid和ddtoroster:yes];\nbreak;\n默认值:\nbreak;\n \n \n\n添加好友,添加好友必须存在于服务器用户上,需要查看是否存在其他好友R方同意。在另一方同意后,刷新好友列表,显示该列表,并将其添加到服务器,其中coredata用于存储个人好友信息。\n\n\n\n\n\n\n\n Buddy页实现文件,跟随代理服务器、数据源数组\n\n\n\n\n\n在viewdidload中初始化该数组,设置e proxy和add friend按钮\n \n \n \n \n \n简化为添加朋友,write dead只能添加“zhang s an”,如果需要添加更多,可以作为借口写入\n \n然后有TableView数据源代理方法\n \n \n \n \n \n \nTableView \n \n数组显然没有jid对象。获取jid对象是在xmppproster代理方法中实现的:\npragma mark xmpproster的代理方法\npragma mark启动方法来检索朋友列表\n-(void)xmpprosterdedbeginpopulating:(xmpproster*)sender \nnslog(@“start retrieving buddy list”);\n \n\npragma mark是re尝试friend list方法\n-(void)xmppresser:(xmppresser*)sender didrecieverosteritem:(ddxmlement*)item \nnslog(@every friend goes this way);\n//获取item属性中的jid字符串,并从中获取jid对象\nnsstring*jidstr=[[item attributeforname:@“jid”]stringvalue];\ n xmppjid*jid=[xmppjid jidwithstring:jidstr];\n//是否添加了它\nif([self-rosterjids-containsObject:jid]);\n返回值;\n \n//向数组添加朋友\n[self-rosterjids-addobject:jid];\n//添加数据后更新UI(表视图更新)\n nsindexpath*indexpath=[nsindxpath-indexpathforrow:自我花名册。杀虫计数-1:0];\n[自表视图InsertRowsatindexpaths:@[indexPath]WithRowAnimation:UITableViewRowAnimationAutomatic];\n \n\nProgma Mark Friend List检索完成的方法\n-(void)XmpPosterDindendPopulating:(XmpPoster*)发件人\nnslog(@“已检索朋友列表”);\n \n\ n\n删除朋友。列表删除、数组删除、服务器删除。\n\n pragma mark删除朋友执行的方法\n-(void)tableview:(uitableview*)tableview committedingstyle:uitableviewcelleddingstyle editingstyle forrowatindexpath:(indexpath nsindxpath*)\nif(editingstyle==uitableviewcelleditingStyledDelete)\n//查找要删除的人\nxmpjid*jid=self。Rosterjids[索引路径。行];\n//从数组中删除\n[自身。rosterjids removeobjectatindex:indexpath row];\n//从用户界面单元格中删除\n[tableview deleterrowsatindexpaths:@[indexpath]withrowanimation:uitableviewrowanimation automatic\n];\n//从服务器中删除\n[[xmppmanager defaultmanager],'6c9967fa458c0683','932ed2ed2czzhbujmcgi7ftbe5zgeq5qc1v',1,'the xmapproster removeuser:jid];\n \n \n\n5。进入聊天页面\n \n \n \n \n \n单击聊天页面的路径\n \n \n \n \n \n聊天页面接受具有jid值的属性\n \n chat \n1。发送纯文本消息\n也封装在xmppmanager中\n//存档聊天信息\n@property(nonatomic,strong)xmppmessagearchivating*xmppmessagearchivating;\n//信息存档上下文\n@property(nonatomic,strong)nsmanagedObjectContext*messagearchivingContext;\n\when init初始化:\n//3。保存聊天记录\n//初始化仓库\nxmpmessagerchivingcoredatastore*messagestorage=[xmppmessagearchivingcoredatastorage sharedInstance];\n//创建消息存档对象\n选择。xmppmessagearchivating=[[xmppmessagearchivating alloc]initwitmessagearchivatingstorage:messagestorage dispatch queue:dispatch_get_main_queue();\n//激活\n[自我。xmppmessagearchivating activate:self-xmppstream];\n//上下文\n选择。messageArchivingContext=消息存储。mainthreadmanagedObjectContext;\n\n在聊天页的viewDidLoad中:\n\n\n\n\n\n\n发送普通消息:\n-(void)dosend \n创建消息对象并指示收件人\nxmpmessage*message=[xmppmessage messagewithtype:@“chat”to:self.chattojid];\n//设置消息内容\n[message addbody:@“hehehehehehehehehehehehehehehehehehehe”]\n//发送消息\n[[xmppmanager defaultmanager]xmppstream sendelement:message];\n成功或不成功的传递有两种代理方法\n \n\n如果消息发送成功,则通过以下代理方法进行传递:\n \n \n \n \n\n \xmppstream的proxy方法\n \n刷新消息的方法需要熟悉coredata \n刷新消息的方法pragma mark \n-(void)reloadmessage \n//获取上下文\nns托管对象上下文*context=[xmppmanager defaultmanager]。messagearchivingcontext;\n//搜索对象\n nsfetchrequest*request=[[nsfetchrequest alloc]init];\n创建实体描述\n nsentitydescription*entity=[nsentitydescription entityforname:@“xmppmessagearchiving\u message\u coredataobject”inManagedObjectContext:context];\n[请求集Entity:entity];\n//查询条件\n nspredicate*pre=[nspredicate predicatewithformat:@“streambarejidstr=%@and barejidstr=%@”,[xmppmanager defaultmanager]。xmppstream。我的吉德,赤身露体,还有自我。查托基德。裸];\n请求。谓词=pre;\n//排序模式\nnsortDescriptor*sort=[[nssortDescriptor alloc]initWithKey:@“timestamp”ascending:yes];\n请求。sortDescriptors=@[sort];\n//执行查询\nnserror*error=nil;\nnsarray*array=[context executefetchRequest:请求错误:&error];\nif(self)。信息。伯爵!=0)\n[自我。消息removeallobjects];\n \n[自我。消息addobjectsfromarray:array];\n[自表视图reloaddata];\n \n\n2。显示聊天记录\n-(nsinteger)tableview:(uitableview*)tableview numberofrowspeagon:(nsinteger)section \n返回自身。信息。计数;\n \n \n-(UITableViewCell*)TableView:(UITableView*)TableView CellForRowatindexPath:(nsIndexPath*)IndexPath \Static NSString*CellIndentifier=@“Cell”;\nUITableViewCell*Cell=[TableView DeQueuersAbellWithIdentifier:CellIndentifier];if(Cell==Nil)\nCell=[[UITableViewcell alloc]initWithStyle:uiTableViewCellStyleValue1 ReuseIdentifier:CellIdentifier];\n \n//在cell上放置聊天信息\n//获取聊天消息\nxmpMessageChiving_message_coreDataObject*message=self。消息[索引路径]。行];\nif(message.isoutgoing==yes)\ncell。详细文本标签。文本=消息。正文;\n \n else \ncell。文本标签。文本=消息。正文;\n \n返回单元格;\n \n \n成功后可以聊天:\n \n \n \n \n \n \n默认图\n \n3。send pictures and other messages(key points)(发送图片和其他信息(关键点))与send video和other files are the same.在xmpp中,您需要将图像转换为nsdata,然后转换为base64字符串进行传输,然后在接收到图像后,将其转换为图像。\n首先,访问系统相册。\n下面是代理程序:\n\n@interface chatviewcontroller()\n\n\n\n\n\n\n从系统相册中选择照片\n\n\n\n\n\n\n发送图片消息\n\n不需要更改cellforrowatindexpath:method,not冻结红色部分。\n \n \n \n \n \n发送图像消息也需要在单元格中更改\n \ni将图像设置为在iOS中进行简单的聊天,实现朋友和聊天        
蜜小助-恋爱/撩妹聊天必备神器
蜜小助App

内置20W+恋爱聊天话术

一键复制解决尬聊话题

相关推荐
女生说困了,情商高的男人都这样回复 女生说滚怎么幽默回复 女生说你算哪块小饼干神回复,卖萌式回复她 适合晚上聊天的开场白,顺利和女生开启聊天
热门推荐
1
聊天开车的污句子 聊到脸红心跳
聊天开车的污句子 聊到脸红心跳

在和自己喜欢的人聊天的时候,总会觉得这些话都不能表达自己的内心的想法,今天小编给大家分享聊天开车的污句子,聊到脸红心跳。彼此心里都知道对方的心意,说这样的一句话既不会尴尬还不失有点小情调的感觉。快来看淘网和小编一起学习聊天开车的污句子吧!

2
高情商女生撩男生的聊天记录 妹子快学起来吧
高情商女生撩男生的聊天记录 妹子快学起来吧

很多女生不懂得怎么撩男生,在和男生聊天的过程中很难让男生心动,其实你只是缺少了一些聊天经验,不如就一起来看看高情商女生撩男生的聊天记录,一定能够帮到你。

3
男生问你是哪里人怎么幽默的回答?
男生问你是哪里人怎么幽默的回答?

有的时候碰到男生问你一些个人问题,要怎么幽默的回答呢?例如:男生问你是哪里人怎么幽默的回答?如果这个男生正好是你喜欢的对象,那么可以说我是你的心上人呀!但如果不是,那么直接说自己来自哪个省就好了,面对男生的提问,女生如果能够幽默的回答,对于关系的发展会更好哦!下面就和看淘网一起看看各种问题如何幽默的回答吧!

4
和已婚女人怎么聊湿的一些话 ***话连篇
和已婚女人怎么聊湿的一些话 ***话连篇

繁星点点跨越银河能否与你相见?看淘网推荐和已婚女人怎么聊湿的一些话。不怕遥远只盼此刻在你身边。往事如烟魂牵梦萦增添我的思念,追寻万年今生情缘不变。一起欣赏一下吧!

5
521个对不起我错了复制 这样道歉太有分量了
521个对不起我错了复制 这样道歉太有分量了

你尝试过连续道歉521遍吗?521个对不起我错了的道歉,她会感动吧?521个对不起我错了复制送给你,这样道歉太有分量了。

6
如何礼貌的问对方姓名 这样让人心生好感
如何礼貌的问对方姓名 这样让人心生好感

在日常生活中,我们要认识一个人首先得知道对方的姓名,可是也不能直接问你叫啥,这样会让对方对你减分,那么如何礼貌的问对方姓名呢,接下来就一起来看看怎么礼貌的问对方姓名吧。

最新推荐
女生说饿了高情商回答,3种回复让她好感加倍
女生说饿了高情商回答,3种回复让她好感加倍
2024-01-31
和女生风趣幽默的开场白句子,让聊天愉快开场
和女生风趣幽默的开场白句子,让聊天愉快开场
2024-01-31
女生说困了,情商高的男人都这样回复
女生说困了,情商高的男人都这样回复
2024-01-31
女生说滚怎么幽默回复
女生说滚怎么幽默回复
2024-01-30
女生说你算哪块小饼干神回复,卖萌式回复她
女生说你算哪块小饼干神回复,卖萌式回复她
2024-01-29
适合晚上聊天的开场白,顺利和女生开启聊天
适合晚上聊天的开场白,顺利和女生开启聊天
2024-01-29