我的问题是这里" body.setStringValue(" Message")"在swift 3.0中不可用,是否有传递消息的替代语法?
func xmppStreamDidAuthenticate(sender: XMPPStream!){
let body = DDXMLElement.elementWithName("body") as! DDXMLElement
let messageID = sender.generateUUID()
body.setStringValue("Message")
let completeMessage = DDXMLElement.elementWithName("message") as! DDXMLElement
completeMessage.addAttributeWithName("id", stringValue: messageID)
completeMessage.addAttributeWithName("type", stringValue: "chat")
completeMessage.addAttributeWithName("to", stringValue: "anotheruser@localhost")
completeMessage.addChild(body)
let active = DDXMLElement.elementWithName("active", stringValue:
"http://jabber.org/protocol/chatstates") as! DDXMLElement
completeMessage.addChild(active)
sender.sendElement(completeMessage)}
答案 0 :(得分:2)
let body = DDXMLElement(name: name, stringValue: stringValue)
答案 1 :(得分:0)
在swift 3.0中,使用以下代码:
let receiverJID = XMPPJID(string:"anotheruser@localhost")
let msg = XMPPMessage(type: "chat", to: receiverJID, elementID:"message1")
msg?.addBody("Hi there!")
stream.send(msg) // Here stream is the XMPPStream