如何将位置发送给XMPP中的其他用户? Swift 3.0

我正在开发聊天应用程序,我需要发送位置其他用户。 (一对一聊天)我已经阅读了xep-0080,但是在XMPP框架中XEP-80没有用。 我也检查了XMPPPubSub模块,但没有得到如何发送用户位置给其他用户。

参考链接:

  1. https://github.com/robbiehanson/XMPPFramework/issues/506
  2. 如何在ios sdk中使用XMPP传递位置?
  3. https://github.com/buddycloud/buddycloud-iOS-client

服务器:ejabber

如果提供了代码片段和教程链接,这是完整的帮助。

经过多次尝试,我已经成功地发送用户自定义位置给其他聊天用户。

使用的扩展名: xep-0080

下面我提到发送位置的function

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) }