xmpp协议之type状态码表示属性

简单扼要,主要简单介绍到xmpp中的presence

  表示XMPP状态的packet。每一个presence都有一个状态。用枚举类型Presence.Type的值表示:

available --(默认)用户空闲状态

unavailable--用户没空看消息

subscribe--请求加别人为好友

subscribed--确认别人对自己的好友请求

unsubscribe--请求删除好友

unsubscribed--拒绝对方的添加请求

error --当前状态packet有错误

内嵌两个Presence.Mode 和Presence.Type。可以使用setStatus自定义当前的状态


小例子:

加好友

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//添加好友
#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];


}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//定义删除好友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];
         
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//拒绝好友请求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];
       
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值