Get full JID from xmpp server or client for IQ Request
-
11-12-2019 - |
Question
I am working on an iOS app that uses the XMPPFramework and openfire xmpp server. I am almost done, but am stuck with getting my iOS to receive IQ request. I was able to receive messages and send IQ request but not receive IQ requests.
I tried sending the IQ request from iOS client and the XMPP server, but the iOS app just ignored the IQ request. After a long time of research, I narrowed down my issue. It turns out that I was sending IQ request to the bare JID. The Bare JID was routed to the server and not directly to the client.
The solution that I found was to get the full JID and set the "to" IQ message to the full JID and not the bare JID. I am having difficulties figuring out how I can get the resource, or make the bare JID to a full JID.
Could someone please give me some suggestions? I want to be able to get the full JID so that I can send IQ request to my iOS client.
Solution
Subscribe to the presence of the person you want to send the IQ to:
<presence type='subscribe' from='me@example.com' to='contact@example.com'/>
They have to accept your subscription:
<presence type='subscribed' to='me@example.com' from='contact@example.com'/>
You'll then start getting presence that includes the full JID from all of their clients:
<presence to='me@example.com' from='contact@example.com/home'/>
If they have a full-featured client, they will send you presence marked up with XEP-0115, so you can tell if their client supports your IQ protocol before you send it to them:
<presence to='me@example.com' from='contact@example.com/home'>
<c xmlns='http://jabber.org/protocol/caps'
hash='sha-1'
node='http://code.google.com/p/exodus'
ver='QgayPKawpkPSDYmwT/WM94uAlu0='/>
</presence>