经过多次尝试后,我已成功将用户自定义位置发送给其他聊天用户。
使用的扩展:xep-0080
下面我为发送位置
public class func sendLocationMessage(msg:String,lat : String ,long : String ,to receiver: String,completionHandler completion:@escaping XMPPMessageMngCompletionHandler){
let body = DDXMLElement.element(withName: "body") as! DDXMLElement
let messageID = XMPPConnect.sharedInstance.xmppStream.generateUUID()
body.stringValue = "Location"
let completeMessage = DDXMLElement.element(withName: "message") as! DDXMLElement
let reuestElemetn = DDXMLElement.element(withName: "request", stringValue: "urn:xmpp:receipts")
completeMessage.addChild(reuestElemetn as! DDXMLNode)
completeMessage.addAttribute(withName: "id", stringValue: messageID!)
completeMessage.addAttribute(withName: "type", stringValue: "chat")
completeMessage.addAttribute(withName: "to", stringValue: receiver)
completeMessage.addChild(body)
let geoElemetn = DDXMLElement.element(withName: "geoloc") as! DDXMLElement
geoElemetn.addAttribute(withName: "xmlns", stringValue: "http://jabber.org/protocol/geoloc")
let latElement = DDXMLElement.element(withName: "lat") as! DDXMLElement
latElement.stringValue = lat
geoElemetn.addChild(latElement);
let lngElement = DDXMLElement.element(withName: "lon") as! DDXMLElement
lngElement.stringValue = long
geoElemetn.addChild(lngElement);
let uriElement = DDXMLElement.element(withName: "uri") as! DDXMLElement
uriElement.stringValue = msg; //google map image url.
geoElemetn.addChild(uriElement)
completeMessage.addChild(geoElemetn)
sharedInstance.didSendMessageCompletionBlock = completion
XMPPConnect.sharedInstance.xmppStream?.send(completeMessage)
}
提功能利用此功能,您还可以发送位置到Android(SMACK LIB)
对于didReceiveMessage代表方法可以检查属性。
if message.attribute(forName: "geoloc") != nil {
self.receivedLocationMsgFromUser(message: message, from: from)
}else{
self.receivedTextMsgFromUser(message: message, msgStr: msg, from: from)
}
能否请你帮我这个问题 - https://stackoverflow.com/questions/47391445/save-carbon-messages-xmppframework-ios 请我在这里停留许多天谢谢。 –
@sohanvanani,我已经读出你的问题,我需要说的第一件事就是把你自己的数据库作为商店信息。如果您使用的是ejabber服务器,请检查此XEP支持或服务器端的所有功能,以便在其他设备上读取离线消息。 –
我使用了开放式的火灾,我安装了监控插件,并且我能够在服务器上存档消息,我希望那些用户的客户端不可用的消息。 –