1

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.

Jay Mehta
  • 1,431
  • 19
  • 40

1 Answers1

0

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)
  }
Jay Mehta
  • 1,431
  • 19
  • 40
  • Can you please help me with this question - https://stackoverflow.com/questions/47391445/save-carbon-messages-xmppframework-ios Please I am stuck here from many days thank you. – sohan vanani Nov 21 '17 at 10:06
  • @sohanvanani , I have read out your question, first thing i need to say that take your own database for store messages. if you are use ejabber server then check this XEP support or everything enable on server side to fetch offline messages on other device. – Jay Mehta Nov 22 '17 at 04:29
  • I used open fire where I installed monitoring plugin and I am able to archive messages on the server I want that messages which are not already available to user's clients. – sohan vanani Nov 22 '17 at 04:44
  • can you provide the stanza that you produce, i.e. the spelled out XML string? – Frederick Nord Oct 09 '18 at 23:43