看淘网-高情商聊天恋爱宝典!| 下载蜜小助-恋爱聊天话术

当前位置: 首页> 聊天攻略

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

发布时间:2019-08-20 21:10:41 作者:xhs 阅读:789
在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中进行简单的聊天,实现朋友和聊天            
相关文章
猜您喜欢
怎么试探前女友想不想复合?

女人是一种让男人捉摸不透的生物,特别是在分手后,就算有复合的想法,表面也会表现的很平静。所以需要男人根据情况自己判断。那到底该怎么去试探前女友想不想复合呢?

2024-02-21

狮子座女生的10个特点,追她之前摸透她的心

狮子座女生可不是那么好追的女生,看上去她平易近人、热情开朗,其实内心却有着自己的小傲娇,狮子座女生的10个特点,追她之前先了解一下吧!

2024-02-21

大街上怎么要女生微信不尴尬,这样要女生乖乖给你

很多时候男生就算在大街上遇到自己喜欢的女生类型,也不敢上来问女生微信,只能看着自己心仪的女生慢慢走远。下面给大家分享大街上怎么要女生微信不尴尬,这样要女生乖乖给你。

2024-02-20

用一个问题测试她喜欢你的方法,女生喜欢你就去追

想知道女生是不是喜欢你,教用一个问题测试她喜欢你的方法:你可以对她说一句话:你好像长胖了一点?(看看女生是什么反应。不过如果男生问出这个问题,可能让女生觉得你情商低,就算女生喜欢你也有一定的风险性)

2024-02-20

女生说心累怎么回复安慰她?分享正确回复方法

女生会在什么情况下说心累呢?可能是她工作上面遇到问题不好解决,让她觉得心累;可能是你对于女生的暗示无动于衷,女生觉得你不落教感到心累。那女生说心累应该怎么回复安慰她呢?

2024-02-19

惹女朋友生气检讨书1000字,哄她不再生你的气

如果男生犯了错惹女朋友生气,那就一定要想办法哄好她,因为是你错了呀。而想要哄好生气的女朋友,那你一定要认识到自己的错误,下面给大家分享惹女朋友生气检讨书1000字,希望能够帮助你哄好你的女朋友。

2024-02-19

婚姻恢复——维持感情让家庭重归平静

婚姻中有幸福的时候,也有不幸福的时候,夫妻应该做到维持好感情,才能顺利让婚姻恢复到幸福的时候,让家庭重归平静。

2024-02-19

怎么追巨蟹座女生?追巨蟹座女生怎么聊天

和巨蟹座女生谈过恋爱之后,就会知道她的内心真的很纯真,不过她性格上的复杂性则是让许多男生疑惑的关键,怎么追巨蟹座女生?追巨蟹座女生的时候要如何聊天呢?

2024-02-18

女朋友说分手后做朋友是什么意思?是真的做朋友么

如果女朋友说分手后做朋友是什么意思呢?如果是还爱着对方那就不应该选择分手,如果是不爱了那大家就应该彻底断了联系,真正深爱过的人是不可能在分手后做朋友的。下面就来分析女朋友的心理。

2024-02-18

暗恋一个人能有多难受?虐心回答句句戳心

暗恋是幸福的,却又是痛苦的,更是难受的,可遇而不可求的爱始终会令人感到绝望,那就是暗恋一个人所体会的难受,明明没有机会却又不想放手真的很痛苦。

2024-02-18