Question

All the codes I use are from https://github.com/robbiehanson/XMPPFramework. Inside the sample code.

In my iOS7 messaging app, I invoke the "connect" function inside XMPP Framework after the user has entered their login credential and clicked the "login" button. The connect function works fine if they entered the correct credentials the first time, but would not work if the user entered the wrong credential. Because this very first line inside connect would simply return TRUE:

 if (![_xmppStream isDisconnected]) {
        return YES;
    }

Which means any further presses on the login button would do nothing.

Should I manually invoke authenticateWithPassword? Is this the right practice assuming a connection between the client and the server has been setup?

Thank you.

Was it helpful?

Solution

You need to use the methods in the delegate to handle authentication. First you need to connect to the server if it's not already connected:

[_xmppStream connectWithTimeout:10 error:&error];

Once the stream is connected to the server the delegate method will be invoked:

- (void)xmppStreamDidConnect:(XMPPStream *)sender;

Inside that method, you can call authenticateWithPassword. If the stream was previously connected (would be the else part of the if you posted) you can just call authenticateWithPassword.

If authentication fails, the following delegate method is called:

- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error;

There you can decide to show a message to the user and start over. If authentication succeeds, the following method is called:

- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top