iosxmppxmppframeworkuser-presence

XMPP Last Seen always return '0' seconds even when user offline long while ago


I am using XMPP RobbieHanson framework, Currently I have enabled Auto subscription ON using following code in didReceivePresence function.

    if([[presence type] isEqualToString:@"subscribe"])
    {
        NSLog(@"presence user wants to subscribe %@",[presence fromStr]);

        [[self xmppRoster] acceptPresenceSubscriptionRequestFrom:[presence from] andAddToRoster:YES];
    }
    else if([[presence type] isEqualToString:@"unsubscribe"])
    {
        [xmppRoster rejectPresenceSubscriptionRequestFrom:[presence from]];
        [xmppRoster revokePresencePermissionFromUser:[presence from]];
    }

I still get the last seen as '0' seconds or 403 forbidden for some users. But at some time i do get they are gone offline or online ,enter code here it means I have and they to have accepted the presence subscription.

    if([[presence type] isEqualToString:@"subscribe"])
    {
        NSLog(@"presence user wants to subscribe %@",[presence fromStr]);

        [[self xmppRoster] acceptPresenceSubscriptionRequestFrom:[presence from] andAddToRoster:YES];
    }
    else if([[presence type] isEqualToString:@"unsubscribe"])
    {
        [xmppRoster rejectPresenceSubscriptionRequestFrom:[presence from]];
        [xmppRoster revokePresencePermissionFromUser:[presence from]];
    }

Solution

  • If the TCP connection is not closed and although you have declared offline to the user the last seen is always mentioned and returned as ZERO.

    you need to disconnect TCP socket by explicit calling the disconnect of the 'xmppstream' in framework.

    Also note that the application that is running in background and gets reconnected due to XMPPReconnect module enables will show the last seen then the server last killed the connection. But if the user reconnects in background mode he will be shown as online.

    For 403 Forbidden the presence should be subscribed to the user , if by any chance he is leaving the system or you are deleting and re-adding the user in the Chat server then the person have to send and accept the subscription request again else 403 error will be thrown.

    I have stopped the background mode enabled for my Apple App so this works fine for me now.

    Any more suggestions are warmly welcomed.