iOS怎么搭建xmpp聊天

iOS怎么搭建xmpp聊天,第1张

iOS 搭建xmpp聊天的具体步骤如下:

聊天室

[cpp] view plain copy

print?

//初始化聊天室

XMPPJID *roomJID = [XMPPJID jidWithString:ROOM_JID]

xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:self jid:roomJID]

[xmppRoom activate:xmppStream]

[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()]

[cpp] view plain copy

print?

//创建聊天室成功

- (void)xmppRoomDidCreate:(XMPPRoom *)sender

{

DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD)

}

[cpp] view plain copy

print?

//加入聊天室,使用昵称

[xmppRoom joinRoomUsingNickname:@"quack" history:nil]

[cpp] view plain copy

print?

//获取聊天室信息

- (void)xmppRoomDidJoin:(XMPPRoom *)sender

{

[xmppRoom fetchConfigurationForm]

[xmppRoom fetchBanList]

[xmppRoom fetchMembersList]

[xmppRoom fetchModeratorsList]

}

如果房间存在,会调用委托

[cpp] view plain copy

print?

// 收到禁止名单列表

- (void)xmppRoom:(XMPPRoom *)sender didFetchBanList:(NSArray *)items

// 收到好友名单列表

- (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items

// 收到主持人名单列表

- (void)xmppRoom:(XMPPRoom *)sender didFetchModeratorsList:(NSArray *)items

房间不存在,调用委托

[cpp] view plain copy

print?

- (void)xmppRoom:(XMPPRoom *)sender didNotFetchBanList:(XMPPIQ *)iqError

- (void)xmppRoom:(XMPPRoom *)sender didNotFetchMembersList:(XMPPIQ *)iqError

- (void)xmppRoom:(XMPPRoom *)sender didNotFetchModeratorsList:(XMPPIQ *)iqError

离开房间

[cpp] view plain copy

print?

[xmppRoom deactivate:xmppStream]

[cpp] view plain copy

print?

//离开聊天室

- (void)xmppRoomDidLeave:(XMPPRoom *)sender

{

DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD)

}

其他代理

[cpp] view plain copy

print?

//新人加入群聊

- (void)xmppRoom:(XMPPRoom *)sender occupantDidJoin:(XMPPJID *)occupantJID

{

DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD)

}

//有人退出群聊

- (void)xmppRoom:(XMPPRoom *)sender occupantDidLeave:(XMPPJID *)occupantJID

{

DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD)

}

//有人在群里发言

- (void)xmppRoom:(XMPPRoom *)sender didReceiveMessage:(XMPPMessage *)message fromOccupant:(XMPPJID *)occupantJID

{

DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD)

}

socket是套接字,在你的语境下,多指传输层网络接口。

webSocket,是一个应用层协议,说的是,目前浏览器实现的一套通信协议,用来解决之前HTTP,请求响应模型不合适的场合。

XMPP,是一个应用层协议,协议基于XML结构设计。

其实websocket是socket的简约实现,与socket相比,可以节省额外的端口占用,直接使用一个公网域名访问。另外协议对报文的流量消耗做了优化。xmpp与websocket比也是比较臃肿的

xmpp是im的使用比较广泛的协议,早期的手机端推送为了省事就用的这种协议,但是后来发现这种协议比较臃肿耗流量,而且对服务器要求比较高

即时通讯肯定少不了通讯协议,在ios开发中基本上都使用基于XMPP 的协议来做即时通讯。在oc下有封装好的XMPP协议库,你在开发时可以调用XMPP的API来进行开发。通讯的服务器可以用ejabberd来搭建。知道的就这些了


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/301306.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-26
下一篇2023-04-26

发表评论

登录后才能评论

评论列表(0条)

    保存