实现XMPPStreamDelegate协议中的方法
时间: 2024-05-01 16:21:32 浏览: 106
XMPPStreamDelegate是一个协议,用于处理XMPPStream的事件和回调。以下是XMPPStreamDelegate协议中的常用方法:
```objective-c
//连接成功
- (void)xmppStreamDidConnect:(XMPPStream *)sender;
//连接超时
- (void)xmppStreamConnectDidTimeout:(XMPPStream *)sender;
//连接断开
- (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error;
//认证成功
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender;
//认证失败
- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error;
//接收到消息
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message;
//接收到好友请求
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence;
//发送消息成功
- (void)xmppStream:(XMPPStream *)sender didSendMessage:(XMPPMessage *)message;
//发送消息失败
- (void)xmppStream:(XMPPStream *)sender didFailToSendMessage:(XMPPMessage *)message error:(NSError *)error;
```
在实现XMPPStreamDelegate协议时,需要将自己的类指定为XMPPStream的代理,如下所示:
```objective-c
XMPPStream *xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
```
然后就可以在实现XMPPStreamDelegate协议中的方法来处理相应的事件和回调了。
阅读全文