如何发送自定义状态(XMPP)?

时间:2015-05-28 07:59:37

标签: xmpp smack

我使用Smack lib。我需要发送此(Android):

<presence type='initialize' location_id='570' user_id='8942'/>.

在Xcode上:

XMPPPresence *presence = [XMPPPresence presence];
    [presence addAttributeWithName:@"location_id" stringValue:[NSString stringWithFormat:@"%lu", (unsigned long)Settings.LocationID]];
    [presence addAttributeWithName:@"user_id" stringValue:[NSString stringWithFormat:@"%lu", (unsigned long)Settings.UserID]];
    [presence addAttributeWithName:@"type" stringValue:@"initialize"];
    [_xmppStream sendElement:presence];

1 个答案:

答案 0 :(得分:0)

你做不到。没有为在线状态的'type'属性定义值'initialize'。也不是'location_id'或'user_id'。如果要将自定义信息添加到节,请使用扩展元素:

<presence ...>
  <myExtension xmlns='myns'>
    <initialize location_id='570' user_id='8942'/>
  </myExtension>
</presence>

另请参阅:https://stackoverflow.com/a/26544842/194894