Too lazy to typeFrom: http://www.cnblogs.com/uvsjoh/archive/2012/09/02/2667348.html
1. In-band Registry
In-band registration means that users who have not activated an account on your server can register a new account through the xmpp protocol. The opposite concept is out-of-band registration. For example
You must register on a specified web page.
If the server allows in-band registration, we can register a new account through a self-developed client. The Protocol relating to in-band registration is a XEP-0077.
2. Use XMPPFramework for in-band registration
XMPPStream. h declares the function for simple in-band registration (user name and password are provided for registration ).
-(BOOL) registerWithPassword :( NSString *) password error :( NSError **) errPtr;
You need to establish a stream connection before registration. Because there is no account, you need to establish an anonymous connection.
NSError * err;
NSString * tjid = [[NSString alloc] initWithFormat: @ "anonymous % @", server. text];
[[Delegate xmppStream] setMyJID: [XMPPJID jidWithString: tjid];
If (! [[Delegate xmppStream] connect: & err])
{
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "failed to connect to the server"
Message: [err localizedDescription]
Delegate: nil
CancelButtonTitle: @ "OK"
OtherButtonTitles: nil];
[AlertView show];
}
After a connection is established, no user verification is required. You can perform the following operations: If the connection is registered, skip the verification step.
- (void)xmppStreamDidConnect:(XMPPStream *)sender{ DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD); isXmppConnected = YES; NSError *error = nil; if (isRegister == YES) return; if (![[self xmppStream] authenticateWithPassword:password error:&error]) { DDLogError(@"Error authenticating: %@", error); }}
XmppStream connect is returned immediately, so the connect return does not indicate that the connection has been established.
[Delegate xmppStream] When isConnected is YES, you can confirm that the connection has been established.
After the connection is established, we can send registration information
NSString * jid = [[NSString alloc] initWithFormat: @ "% @", user. text, server. text];
[[Delegate xmppStream] setMyJID: [XMPPJID jidWithString: jid];
NSError * error = nil;
If (! [[Delegate xmppStream] registerWithPassword: password. text error: & error])
{
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "Account creation failed"
Message: [error localizedDescription]
Delegate: nil
CancelButtonTitle: @ "OK"
OtherButtonTitles: nil];
[AlertView show];
}
RegisterWithPassword: the error method is returned immediately.
You need to use the proxy method to determine whether the registration is successful.
If the registration is successful, it will call:-(void) xmppStreamDidRegister :( XMPPStream *) sender
If the registration fails, the system will call-(void) xmppStream :( XMPPStream *) sender didNotRegister :( NSXMLElement *) error.
-(Void) xmppStreamDidRegister :( XMPPStream *) sender {DDLogVerbose (@ "% @: % @", THIS_FILE, THIS_METHOD); registerSuccess = YES; UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "Account Created successfully" message: @ "" delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alertView show];}-(void) xmppStream :( XMPPStream *) sender didNotRegister :( NSXMLElement *) error {DDLogVerbose (@ "% @: % @", THIS_FILE, THIS_METHOD ); UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "Account creation failed" message: @ "username conflict" delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alertView show];}