您好,登錄后才能下訂單哦!
簡單扼要,主要簡單介紹到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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。