Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 405
manishsharma93 Avatar asked Mar 22 '16 16:03

manishsharma93


1 Answers

-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
    }
like image 131
nikBhosale Avatar answered Sep 28 '22 21:09

nikBhosale