How to pass location using XMPP in ios sdk?

2019-04-17 04:40发布

问题:

I have to pass location using XMPP. How can I do it?

回答1:

As I am give you suggestion regarding single chat. as you are prepare xml formate for sending message in XMPP as like bellowed.

NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:textvalue];

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
[message addChild:body];

[[self xmppStream] sendElement:message];

Here add two extra attribute for latitude and longitude as like below.

NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:textvalue];

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[jid full]];
[message addAttributeWithName:@"latitude" stringValue:@"22.2345"];
[message addAttributeWithName:@"longitude" stringValue:@"42.2345"];
[message addChild:body];

[[self xmppStream] sendElement:message];

there won't be any problem in sending message while adding two extra parameter. and at other end while received this message you can fetched latitude and longitude from message and used it as per your requirements.

Hope this help you.



标签: ios xmpp