首先,由于我的好奇心,这可能是一个重复的问题。
我正在创建一个基于xmpp框架的聊天应用程序。现在我面临着一个问题,当用户输入我希望其状态的用户将被发送给他聊天的目标用户。
我正在使用此代码:
func sendComposingChat() {
let sendToUser = strUserName + "@" + kAppDelegate.strJSenderDomain
let sendFromUser = strMyUserName + "@" + kAppDelegate.strJDomain
let messageBody = XMLElement.element(withName: "message") as! XMLElement
messageBody.addAttribute(withName: "type", stringValue: "chat")
messageBody.addAttribute(withName: "toUserId", stringValue: "1")
messageBody.addAttribute(withName: "to", stringValue: sendToUser)
messageBody.addAttribute(withName: "from", stringValue: sendFromUser)
messageBody.addAttribute(withName: "senderId", stringValue: "1")
let composing = XMLElement.element(withName: "composing") as! XMLElement
composing.addAttribute(withName: "xmlns", stringValue: "http://jabber.org/protocol/chatstates")
messageBody.addChild(composing)
kAppDelegate.xmppStream?.send(messageBody)
}
收到我以这种方式管理的状态:
print("message = \(message.hasComposingChatState())")
let strComposing = message.attribute(forName: "composing")?.stringValue
print("strComposing = \(strComposing)"
if strComposing?.characters.count == 0 {
print("User is typing")
}
strComposing显示nil,我无法显示输入状态。
请提出我在这里缺少的内容。