简单扼要,主要简单介绍到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];
}