3

プレゼンスを変更して、dnd/away などを表示するにはどうすればよいですか?

XMPPPresence *presence = [XMPPPresence presenceWithType:status];
[[[self appDelegate] xmppStream] sendElement:presence];

statusNSStringonline/unavailable/away/busy/invisible に設定した です。

オンラインになったとき、および/または利用できないときにのみ機能します。

my でプレゼンスを送信した後の様子は次のxmppStreamとおりです。

<presence type="away"><x xmlns="vcard-temp:x:update"><photo/></x></presence>
4

3 に答える 3

14

クライアントのステータスを変更するには、次の簡単なコードを使用する必要があります。

XMPPPresence *presence = [XMPPPresence presence];
NSXMLElement *status = [NSXMLElement elementWithName:@"status"];
[status setStringValue:@"online/unavailable/away/busy/invisible"];
[presence addChild:status];
[[self xmppStream] sendElement:presence];

これは単に、クライアントのステータスを変更するための鍵は、プレゼンスにステータス要素を追加することによることを意味します。管理パネルのユーザーアイコンにカーソルを合わせた場合にのみ、openfireサーバーに「使用可能/オフライン」ステータスが表示されることに注意してください。ただし、これで混乱することはありません。クライアントが送信し、他の人が受信したプレゼンスメッセージを確認するだけで、設定したステータス(「オンライン/利用不可/離れている/忙しい/見えない」)が表示されます。

于 2012-02-14T15:11:36.120 に答える
5

上記の回答に加えて、要素<show>と組み合わせて使用​​する必要がある要素もあり<status>ます。両方の要素を使用することで、可用性の状態ごとにユーザーのプレゼンスをカスタマイズできます。

デフォルト: 利用可能 / オフライン

使用方法<show>: 利用可能 / 話中 / 退席中 / 長時間退席中 / オフライン

で使用<show>する<status>: 「自由にチャット」/「仕事で忙しい」/「会議中」/「ランチに出かける」。


この方法で Openfire を使用する場合: [ユーザー セッション] > [プレゼンス] 列に、次のように表示されます。

  1. ユーザーごとに異なる色のアイコン (例: 使用可能な場合は緑、使用の場合は赤など)

  2. アイコンの横の説明テキスト (例: 「会議中」)


子要素の存在

XMPP でプレゼンスの種類を変更できる要素は 3 つあります。

  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').

この要素が指定されていない場合、ユーザーはオンラインで利用可能であると見なされます。

状態

<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"

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];

これで、カスタマイズしたユーザーの存在がサーバーに正確に反映されます。

関連項目: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence

于 2014-07-16T05:44:13.107 に答える