将XMPPPresence更改为Away/Busy/Invisible

Vin*_*lso 3 xmpp objective-c user-presence ios xmppframework

你如何改变你的存在以显示dnd/away等?

XMPPPresence *presence = [XMPPPresence presenceWithType:status];
[[[self appDelegate] xmppStream] sendElement:presence];
Run Code Online (Sandbox Code Playgroud)

statusNSString我设置为在线/不可用/离开/忙/不可见的.

它仅在我上线和/或不可用时才有效.

以下是我在发送状态后的样子xmppStream:

<presence type="away"><x xmlns="vcard-temp:x:update"><photo/></x></presence>
Run Code Online (Sandbox Code Playgroud)

Fut*_*020 14

要更改客户端的状态,您需要使用以下简单代码:

XMPPPresence *presence = [XMPPPresence presence];
NSXMLElement *status = [NSXMLElement elementWithName:@"status"];
[status setStringValue:@"online/unavailable/away/busy/invisible"];
[presence addChild:status];
[[self xmppStream] sendElement:presence];
Run Code Online (Sandbox Code Playgroud)

这只是意味着更改客户端状态的关键是向您的状态添加状态元素.请注意,当您将鼠标悬停在管理面板中的用户图标上时,openfire服务器将仅显示"可用/离线"状态.这不应该让你感到困惑.您只需检查客户端发送的状态消息,并由其他人接收,这些消息将显示您已设置的状态("在线/不可用/离开/忙/不可见").


Kei*_*OYS 5

除上述答案外,还有一个<show>元素应与该<status>元素结合使用。通过使用这两个元素,您可以为每个可用性状态自定义用户的状态。

默认值:可用/离线

通过使用<show>:可用/忙/离/远距/脱机

通过<show><status>“免费聊天” /“辛苦工作” /“开会” /“外出吃午餐”一起使用。


如果您通过以下方法使用Openfire:在“用户会话”>“在线状态”列中,您将看到:

  1. 每个用户使用不同颜色的图标(例如,绿色表示可用,红色表示忙碌等)

  2. 图标旁边的描述性文字(例如“ 正在开会 ”)


存在子元素

有3个元素可以更改XMPP中的状态类型。

  1. <show/>
  2. <status/>
  3. <priority/>我们将排除讨论

显示

<show> 指定用户的可用性状态。

必须根据下面的列表指定元素的值。

"chat" -- user is actively interested in chatting.
"dnd"  -- user is busy (dnd a.k.a 'Do Not Disturb').
"away" -- user is temporarily away.
"xa"   -- user is away for an extended period (xa a.k.a. 'eXtended Away').
Run Code Online (Sandbox Code Playgroud)

如果未提供此元素,则假定用户仅处于联机状态且可用。

状态

<status> 描述用户的可用性状态。它通常与<show>元素结合使用以提供可用性状态的详细描述。

元素的值可以是任何描述性文字。例如:

"Available to chat" -- can be used for "chat"
"Busy at work"      -- can be used for "dnd"
"In a meeting"      -- can be used for "away"
"On a vacation"     -- can be used for "xa"
Run Code Online (Sandbox Code Playgroud)

在Objective-C中的用法

这是您应该在代码中应用以上概念的方法。

// Initialize variables
XMPPPresence *presence = [XMPPPresence presence];
NSXMLElement *show = [NSXMLElement elementWithName:@"show"];
NSXMLElement *status = [NSXMLElement elementWithName:@"status"];

// If user is available
[show setStringValue:@"chat"];
[status setStringValue:@"Available to chat"];

// If user is busy
[show setStringValue:@"dnd"];
[status setStringValue:@"Busy at work"];

// If user is away
[show setStringValue:@"away"];
[status setStringValue:@"In a meeting"];

// If user is away for a long period of time
[show setStringValue:@"xa"];
[status setStringValue:@"On a vacation"];

// Add the XML child elements to XMPPPresence
[presence addChild:show];
[presence addChild:status];

// Update new presence to server
[[[self appDelegate] xmppStream] sendElement:presence];
Run Code Online (Sandbox Code Playgroud)

到这里,您的自定义用户的状态现在将准确地反映在您的服务器中。

另请参阅:可扩展消息传递和状态协议(XMPP):即时消息传递和状态