2016-11-12 58 views
1

我的问题是,这里“body.setStringValue(”消息“)”在swift 3.0中不可用,是否有任何其他语法传递消息?XMPP语法不赞成在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: "[email protected]") 
completeMessage.addChild(body) 

let active = DDXMLElement.elementWithName("active", stringValue: 
    "http://jabber.org/protocol/chatstates") as! DDXMLElement 
completeMessage.addChild(active) 
sender.sendElement(completeMessage)} 
+0

这里我得到了迅速的版本解决这个问题,我们可以写出像“body.stringValue = “Hello报文”! – Bucket

回答

2
let body = DDXMLElement(name: name, stringValue: stringValue) 
0

在SWIFT 3.0,使用下面的代码:

let receiverJID = XMPPJID(string:"[email protected]") 
let msg = XMPPMessage(type: "chat", to: receiverJID, elementID:"message1") 
msg?.addBody("Hi there!") 
stream.send(msg) // Here stream is the XMPPStream