title: Authenticate Anonymously using XMPP framework in iOS
body: <p>I want to connect to openfire server anonymously using xmpp framework in iOS. I can connect to open fire by providing the JID and PW. However when I tried to connect anonymously it says "The server doesn't support anonymous authentication".</p>
  
  <p>I'm using a button in xib file. When its clicked below code executes:</p>
  
  <pre><code>- (IBAction)login:(id)sender {
  
      [[self appDelegate]connect];
  
      NSError *authenticationError = nil;
      [self.xmppStream authenticateAnonymously:&amp;authenticationError];
  }
  </code></pre>
  
  <p>and below is the code for connect method:</p>
  
  <pre><code>- (BOOL)connect {
  
      [self setupStream];
      xmppStream.hostName = @"abc.xyz.com";
      //xmppStream.hostName = @"Virtuals-MacBook-Pro.local ";
  
      NSString *jabberID = [[NSUserDefaults standardUserDefaults] stringForKey:@"userID"];
      NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:@"userPassword"];
  
      if (![xmppStream isDisconnected]) {
          return YES;
      }
  
      if (jabberID == nil || myPassword == nil) {
  
          return NO;
      }
  
      [xmppStream setMyJID:[XMPPJID jidWithString:jabberID]];
      password = myPassword;
  
      NSError *error = nil;
      if (![xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&amp;error])
      {
          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                              message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
                                                             delegate:nil
                                                    cancelButtonTitle:@"Ok"
                                                    otherButtonTitles:nil];
          [alertView show];
          //[alertView release];
  
  
          return NO;
      }
  
      return YES;
  }
  </code></pre>