【问题标题】:XMPP syntax deprecated in swift 3.0swift 3.0 中不推荐使用 XMPP 语法
【发布时间】:2017-03-26 12:28:57
【问题描述】:

我的问题是,这里的“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)}

【问题讨论】:

  • 这里我得到了这个问题的解决方案,我们可以在 swift 版本中写成 "body.stringValue = "Hello Message!"

标签: ios swift3 xmppframework


【解决方案1】:
let body = DDXMLElement(name: name, stringValue: stringValue)

【讨论】:

    【解决方案2】:

    在 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
    

    【讨论】:

      猜你喜欢
      • 2018-03-15
      • 1970-01-01
      • 2023-03-04
      • 2017-06-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多