Search code examples
iphoneobjective-ccocoa-touchxmppxmppframework

XMPPFramework : can I determine the online/offline status of a user at all?


How would I determine if a user is online/offline using XMPPFramework for iPhone?

I have their JID etc etc. Is there a way of requesting a presence or something?

Thank you.


Solution

  • Have you checked out the source code of the XMPPFramework sample project?

    If I remember correctly, this should be the relevant code snippet:

    // Subscribe to the buddy's presence
    // 
    // <presence to="bareJID" type="subscribe"/>
    
    NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
    [presence addAttributeWithName:@"to" stringValue:[jid bare]];
    [presence addAttributeWithName:@"type" stringValue:@"subscribe"];
    
    [xmppStream sendElement:presence];
    

    And the callback your stream delegate gets should be

    - (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence;
    

    I assume that you already have the xmmpframework source, if not, you can clone the repository here

    hg clone https://xmppframework.googlecode.com/hg/ xmppframework
    

    The sample projects are in the "Xcode" folder.