您好,登录后才能下订单哦!
简单扼要,主要简单介绍到xmpp中的presence
表示XMPP状态的packet。每一个presence都有一个状态。用枚举类型Presence.Type的值表示:
available --(默认)用户空闲状态
unavailable--用户没空看消息
subscribe--请求加别人为好友
subscribed--确认别人对自己的好友请求
unsubscribe--请求删除好友
unsubscribed--拒绝对方的添加请求
error --当前状态packet有错误
内嵌两个Presence.Mode 和Presence.Type。可以使用setStatus自定义当前的状态
小例子:
加好友
//添加好友 #pragma mark 加好友 - (void)XMPPAddFriendSubscribe:(NSString *)name { //XMPPHOST 就是服务器名, 主机名 NSXMLElement *mes = [NSXMLElement elementWithName:@"presence"]; [mes addAttributeWithName:@"xmlns" stringValue:@"jabber:client"]; //消息类型 [mes addAttributeWithName:@"type" stringValue:@"subscribe"]; [mes addAttributeWithName:@"to" stringValue:name]; [mes addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",[[ShpadDataCenter AppData] loginname],@"ay130415223308469c09"]]; //发送消息 [[[ShpadXMPPService sharedInstance] xmppStream] sendElement:mes]; }
//定义删除好友XMPP
#pragma mark 加好友
- (void)XMPPDeleteFriendSubscribe:(NSUInteger)row
{
//XMPPHOST 就是服务器名, 主机名
NSXMLElement *mes = [NSXMLElement elementWithName:@"presence"];
[mes addAttributeWithName:@"xmlns" stringValue:@"jabber:client"];
//消息类型
[mes addAttributeWithName:@"type" stringValue:@"unsubscribe"];
[mes addAttributeWithName:@"to" stringValue:[(BuddyEntity *)[self._allFriends objectAtIndex:row] userId]];
[mes addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",[[ShpadDataCenter AppData] loginname],@"ay130415223308469c09"]];
//发送消息
[[[ShpadXMPPService sharedInstance] xmppStream] sendElement:mes];
}
//定义删除好友XMPP #pragma mark 删除好友 - (void)XMPPDeleteFriendSubscribe:(NSUInteger)row { //XMPPHOST 就是服务器名, 主机名 NSXMLElement *mes = [NSXMLElement elementWithName:@"presence"]; [mes addAttributeWithName:@"xmlns" stringValue:@"jabber:client"]; //消息类型 [mes addAttributeWithName:@"type" stringValue:@"unsubscribe"]; [mes addAttributeWithName:@"to" stringValue:[(BuddyEntity *)[self._allFriends objectAtIndex:row] userId]]; [mes addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",[[ShpadDataCenter AppData] loginname],@"ay130415223308469c09"]]; //发送消息 [[[ShpadXMPPService sharedInstance] xmppStream] sendElement:mes]; }
//拒绝好友请求xmpp #pragma mark 拒绝好友 - (void)XMPPRejectFriendSubscribe:(id) sender { //XMPPHOST 就是服务器名, 主机名 NSXMLElement *mes = [NSXMLElement elementWithName:@"presence"]; [mes addAttributeWithName:@"xmlns" stringValue:@"jabber:client"]; //消息类型 [mes addAttributeWithName:@"type" stringValue:@"unsubscribed"]; [mes addAttributeWithName:@"to" stringValue:[self.userInfo objectForKey:@"userName"]]; [mes addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",[[ShpadDataCenter AppData] loginname],@"ay130415223308469c09"]]; //发送消息 [[[ShpadXMPPService sharedInstance] xmppStream] sendElement:mes]; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。