1
votes

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.

Reference links :

  1. https://github.com/robbiehanson/XMPPFramework/issues/506
  2. How to pass location using XMPP in ios sdk?
  3. https://github.com/buddycloud/buddycloud-iOS-client

Server : ejabber

It's help full if provide snippet of code and tutorial link.

1

1 Answers

0
votes

After many try i have successfully send user custom location to other chat user.

Used extensions : 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)
}

From this function you can also send location to Android(SMACK Lib)

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