您好,登錄后才能下訂單哦!
簡單扼要,主要簡單介紹到xmpp中的presence
表示XMPP狀態(tài)的packet。每一個presence都有一個狀態(tài)。用枚舉類型Presence.Type的值表示:
available --(默認)用戶空閑狀態(tài)
unavailable--用戶沒空看消息
subscribe--請求加別人為好友
subscribed--確認別人對自己的好友請求
unsubscribe--請求刪除好友
unsubscribed--拒絕對方的添加請求
error --當前狀態(tài)packet有錯誤
內(nèi)嵌兩個Presence.Mode 和Presence.Type??梢允褂胹etStatus自定義當前的狀態(tài)
小例子:
加好友
//添加好友 #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"]]; //發(fā)送消息 [[[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"]];
//發(fā)送消息
[[[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"]]; //發(fā)送消息 [[[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"]]; //發(fā)送消息 [[[ShpadXMPPService sharedInstance] xmppStream] sendElement:mes]; }
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。