I’m trying to add a new buddy to the user’s roster using this line of code:
XMPPJID jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@localhost",
addBuddyTextField.text]];
[appDelegate.xmppRoster addUser:jid withNickname:addBuddyTextField.text];
This works. The other users gets the subscription request notice, he can accept it and everything works fine. The new buddy will be added into the XMPPRosterMemoryStorage and will show on the [XMPPRosterMemoryStorage unsortedUsers] NSArray so that the current roster with all his buddys can be presented on the UI.
But once the users logs out and restarts the application the whole roster is gone, with all his buddys he added. [XMPPRoster fetchRoster] and the following method [XMPPRosterMemoryStorage unsortedUsers] return an NSArray with no items in it.
Do I have to post the buddy update (add, removal) to the XMPPServer? Or is Roster not supported by my XMPPserver (ejabberd)?
Here’s the code I use to activate XMPPRoster:
xmppRosterMemStorage = [[XMPPRosterMemoryStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterMemStorage
dispatchQueue:dispatch_get_main_queue()];
[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = false;
xmppRoster.autoFetchRoster = true;
[xmppRoster activate:xmppStream];
[xmppRoster fetchRoster];
From the discussion above, it sounds like your server is getting your roster requests just fine. Using your setup code I can’t reproduce the problem you’re having.
You could try turning on logging and seeing if reading the protocol log helps you understand what’s happening:
Or try my test code with your server, and if the problem goes away, start working from there:
It also works if I move the roster setup code to
-xmppStreamDidAuthenticate, however I do need to manually invoke-fetchRosterin that case.