Question

For changing my logged status I used the following code:

    XMPPPresence *presence = [XMPPPresence presenceWithType:@"away"];
    [[self xmppStream] sendElement:presence];

But I am not getting the reference of [self xmppStream]. So I changed to the following code:

    XMPPPresence *presence = [XMPPPresence presence];
    NSXMLElement *status = [NSXMLElement elementWithName:@"status"];
    [status setStringValue:@"away"];
    [presence addChild:status];
    NSError *error = nil;

    xmppStream = [[XMPPStream alloc] init];
    [xmppStream disconnect];
    NSString *myJID = [NSString stringWithFormat:@"%@", appDelegate.jid];
    XMPPJID *JID;        
    JID = [XMPPJID jidWithString:myJID];
    NSLog(@"%@",JID);
    [xmppStream setMyJID:JID];
    xmppStream.hostName=@"talk.google.com";

    [xmppStream connect:&error];        
    [xmppStream sendElement:presence];

Still not getting the changed status. Please share your ideas. Thanks in advance.

Was it helpful?

Solution

You can change your status immediately after you're logged in via goOnline method as it is called after xmppStreamDidAuthenticate.

- (void)goOnline
{
    // Initialize XMPPPresence variable
    XMPPPresence *presence = [XMPPPresence presence];

    // Initialize XML element <show/> for specifying your status
    NSXMLElement *show = [NSXMLElement elementWithName:@"show"];

    // Initialize XML element <status/> for describing your status
    NSXMLElement *status = [NSXMLElement elementWithName:@"status"];

    // If you want your user status to be shown as "Available"
    [show setStringValue:@"chat"];
    [status setStringValue:@"Available"];

    // If you want your user status to be shown as "Busy"
    [show setStringValue:@"dnd"];
    [status setStringValue:@"Busy"];

    // If you want your user status to be shown as "Away"
    [show setStringValue:@"away"];
    [status setStringValue:@"Away"];

    // If you want your user status to be shown as "Off-day"
    [show setStringValue:@"xa"];
    [status setStringValue:@"Off-day"];

    // Add the XML elements to XMPPPresence
    [presence addChild:show];
    [presence addChild:status];

    // Update new presence to server
    [xmppStream sendElement:presence];
}

For more information and an explanation to my code above, visit Change XMPPPresence to Away/Busy/Invisible.

OTHER TIPS

You have to wait until after you're connected to send stanzas, by listening for xmppStreamDidAuthenticate on the delegate.

Also, don't bother to set the to or from JID when broadcasting your presence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top