如何在XMPP中将位置发送给其他用户?斯威夫特3.0 [英] How to send location to other user in XMPP ? Swift 3.0
问题描述
我正在开发聊天应用程序,因为我需要向其他用户发送位置信息. (一对一聊天) 我已阅读 xep-0080 ,但是在XMPP框架XEP-80类中不可用. 我还检查了XMPPPubSub模块,但没有得到如何将用户位置发送给其他用户的方法.
I am developing chat app in that i need to send location other user. (One to One Chat) I have read xep-0080 but in XMPP framework XEP-80 class not avail-be. I have also checked XMPPPubSub Module but not getting how to send user location to other user.
参考链接:
- https://github.com/robbiehanson/XMPPFramework/issues/506
- 如何在iOS SDK中使用XMPP传递位置? /a>
- https://github.com/buddycloud/buddycloud-iOS-client
- https://github.com/robbiehanson/XMPPFramework/issues/506
- How to pass location using XMPP in ios sdk?
- https://github.com/buddycloud/buddycloud-iOS-client
服务器:ejabber
Server : ejabber
如果提供代码段和教程链接,将对您有很大帮助.
It's help full if provide snippet of code and tutorial link.
推荐答案
经过多次尝试,我已成功将用户自定义位置发送给其他聊天用户.
After many try i have successfully send user custom location to other chat user.
使用的扩展名: xep-0080
下面我提到发送位置的功能
Below i have mention function for send Location
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)
From this function you can also send location to Android(SMACK Lib)
对于 didReceiveMessage 委托方法,您可以检查属性.
For didReceiveMessage delegate method you can check attribute.
if message.attribute(forName: "geoloc") != nil {
self.receivedLocationMsgFromUser(message: message, from: from)
}else{
self.receivedTextMsgFromUser(message: message, msgStr: msg, from: from)
}
这篇关于如何在XMPP中将位置发送给其他用户?斯威夫特3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!