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

How to send custom presence (XMPP)?

我使用 Smack 库。我需要发送这个(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];

你不能。未为状态的 'type' 属性定义值 'initialize'。 'location_id' 或 'user_id' 也不是。如果要向节添加自定义信息,请使用扩展元素:

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

另请参阅: