manishsharma93
manishsharma93

Reputation: 1049

How to check the presence of Particular user online/offline status through XMPP server

I am building an app where I need to find online/offline status of only those users with whom I have exchanged messages in past. Not all the users available on the server. Thanks in advance.

Upvotes: 8

Views: 3344

Answers (3)

nikBhosale
nikBhosale

Reputation: 541

-You can get particular user's online/offline status using XMPPIQ You need to create XMPPIQ with 'type get' as following

let query = XMLElement(name: "query", xmlns: "jabber:iq:last")
        let streamUUID = self.xmppStream.generateUUID()
        let iq = XMPPIQ(type: "get", to: XMPPJID(string: jid) , elementID: streamUUID , child: query)
        self.xmppStream.send(iq)
        return streamUUID!

then there is delegate method in XMPPStreamDelegate protocol named 'didReceive iq:', you need to provide handle IQ result in thi smethod as follows,

 func xmppStream(_ sender: XMPPStream!, didReceive iq: XMPPIQ!) -> Bool {
        if iq.isResultIQ() {
            iq.lastActivitySeconds() == 0{
               print("user is online")
            }else{
               print("user is offline") 
            }
        }
        return false
    }

Upvotes: 3

michalwski
michalwski

Reputation: 369

To have the presence (mentioned by Nyco) pushed to the client, you would have to subscribe to the other user's presence. It's described here: http://xmpp.org/rfcs/rfc6121.html#sub

Upvotes: 0

Nyco
Nyco

Reputation: 136

Presences are broadcast, so you just receive them when the "happen". There are presence probes in the context of a remote server (S2S, server-to-server). But there is no polling.

Upvotes: 0

Related Questions