XMPPRoster will not send new friends to the XMPP server

I am trying to add a new friend to the user list using this line of code:

XMPPJID jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@localhost", addBuddyTextField.text]]; [appDelegate.xmppRoster addUser:jid withNickname:addBuddyTextField.text]; 

It works. Other users receive a notification about the subscription request, he can accept it, and everything works fine. A new buddy will be added to XMPPRosterMemoryStorage and displayed in [XMPPRosterMemoryStorage unsortedUsers] NSArray so that the current list with all its buddys can be presented in the user interface.

But as soon as users log out and restart the application, the entire list will disappear and all his friends will add it. [XMPPRoster fetchRoster] and the following method [XMPPRosterMemoryStorage unsortedUsers] returns an NSArray with no elements in it.

Should I post a buddy update (add, delete) on XMPPServer? Or is the list not supported by my XMPPserver (ejabberd)?

Here is the code that 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]; 
+4
source share
1 answer

In the discussion above, it sounds like your server is getting your list requests very well. Using the installation code, I can not reproduce the problem that you encountered.

You can try turning on logging and see if the protocol log reads what you understand:

 #import "DDTTYLogger.h" - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [DDLog addLogger:[DDTTYLogger sharedInstance]]; ... 

Or try my test code with your server, and if the problem goes away, get started from there:

 #import "AppDelegate.h" #import "XMPPFramework.h" #import "DDTTYLogger.h" #import "DDLog.h" static const int ddLogLevel = LOG_LEVEL_VERBOSE; NSString * const XMPPAuthenticationMethodPlain = @"Plain"; NSString * const XMPPAuthenticationMethodDigestMD5 = @"Digest-MD5"; NSString * const OptionHostName = @"..."; NSUInteger const OptionPort = 5222; BOOL const OptionOldSchoolSSL = NO; NSString * const OptionJID = @"..."; NSString * const OptionAuthenticationMethod = @"Digest-MD5"; NSString * const OptionPassword = @"..."; @interface AppDelegate () <XMPPStreamDelegate, XMPPRosterMemoryStorageDelegate> @property (retain) XMPPStream *xmppStream; @property (retain) XMPPRosterMemoryStorage *xmppRosterMemStorage; @property (retain) XMPPRoster *xmppRoster; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [DDLog addLogger:[DDTTYLogger sharedInstance]]; self.xmppStream = [[XMPPStream alloc] init]; [self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()]; self.xmppStream.hostName = OptionHostName; self.xmppStream.hostPort = OptionPort; self.xmppStream.myJID = [XMPPJID jidWithString:OptionJID]; self.xmppRosterMemStorage = [[XMPPRosterMemoryStorage alloc] init]; self.xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:self.xmppRosterMemStorage dispatchQueue:dispatch_get_main_queue()]; [self.xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()]; [self.xmppRoster activate:self.xmppStream]; NSError *error = nil; if (OptionOldSchoolSSL) [self.xmppStream oldSchoolSecureConnect:&error]; else [self.xmppStream connect:&error]; } -(void)applicationWillTerminate:(NSNotification *)notification { [self.xmppStream removeDelegate:self]; [self.xmppStream disconnect]; } -(void)xmppStreamDidConnect:(XMPPStream *)sender { Class authClass = nil; if ([OptionAuthenticationMethod isEqual:XMPPAuthenticationMethodPlain]) authClass = [XMPPPlainAuthentication class]; else if ([OptionAuthenticationMethod isEqual:XMPPAuthenticationMethodDigestMD5]) authClass = [XMPPDigestMD5Authentication class]; else { DDLogWarn(@"Unrecognized auhthentication method '%@', falling back on Plain", OptionAuthenticationMethod); authClass = [XMPPPlainAuthentication class]; } id<XMPPSASLAuthentication> auth = [[authClass alloc] initWithStream:sender password:OptionPassword]; NSError *error = nil; if (![sender authenticate:auth error:&error]) NSLog(@"Error authenticating: %@", error); } -(void)xmppRosterDidPopulate:(XMPPRosterMemoryStorage *)sender { NSLog(@"users: %@", [sender unsortedUsers]); // My subscribed users do print out } @end 

It also works if I switch to the roster installation code on -xmppStreamDidAuthenticate , however in this case I need to manually call -fetchRoster .

+1
source

All Articles