【问题标题】:XMPPMessage timeXMPP消息时间
【发布时间】:2014-12-30 15:55:27
【问题描述】:

我正在使用适用于 iOS 的 XMPPFramework,我需要显示消息的日期和时间。 经过一番搜索,我认为我应该使用XMPPAutoTime 模块,但我没有找到一些示例。

我在流设置中使用过:

xmppAutoTime = [[XMPPAutoTime alloc] initWithDispatchQueue:dispatch_get_main_queue()];
[xmppAutoTime activate:self.xmppStream];

我的发送消息方法如下:

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:to];

[message addChild:[XMPPTime timeElement]];

NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:text];
[message addChild:body];

我的 XML 看起来像:

<message type="chat" to="toJID">
    <time xmlns="urn:xmpp:time">
        <tzo>+03:00</tzo>
        <utc>2014-12-30T15:24:22Z</utc>
    </time>
    <body>message text</body>
</message>

所以你可以看到我有时间,这是正确的。问题是我如何将它用于XMPPMessage

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message

【问题讨论】:

    标签: ios xmpp xmppframework


    【解决方案1】:

    我也在研究 XMPP,很高兴您有这个问题,因为我不知道如何为我发送的消息添加时间。

    无论如何,我不确定是否有更简单或更正确的方法,但我使用这个:

    [[message elementForName:@"time"] elementForName:@"utc"]
    

    didReceiveMessage 委托方法中从 XML 中提取时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多