For chat applications, users have to register by creating their account or using social networking accounts like Facebook or Twitter. This registration process can be done by using normal web services running on our servers and saving the details in the database. But for this, we need web services for registration and database to save the user's registration details along with you will have to care of many scenarios like invalid user names, email etc at the time registration process. So it's definitely a time taking and tedious approach to own the XMPP registration process.
The good news here is, if you are using XMPP as your char server, you are then on safe hands. Why because XMPP creates it's own database also at the time of XMPP server installation and also the iOS XMPP framework provides you the methods for user registration which is vey simple when compared to our custom .net/PHP/Java web services that we need to write for registration process.
Here is the sample Objective C code for XMPP user registration.
XMPPStream object has a method called registerWithElemnets, which takes an array of xml elements like username, password, email etc. This approach of using builtin XMPP method for registration is simple and the most important thing is this service is very fast in speed or performance compared to our custom web services. And also it takes care of the scenarios like 'username already exists' etc. So it's simple but powerful approach to follow for user registration in a iOS chat application using Objective-c.
Now, we are able to register the user using the XMPP registerWithElemnets method. Though it's simple, we need to know whether the registration process is successful or not and if not what are the issues that failed registration process. XMPP has delegate methods for successful registration and also for failed registration.
- The delegate method for successful registration process is xmppStreamDidRegister. If this delegate callback method is called your XMPP user registration process is successful. You can proceed use to your application.
Here is the Objective C code for xmppStreamDidRegister delegate method.
- The delegate method for unsuccessful registration process is didNotRegister. If this delegate callback method is called your XMPP user registration process is failed. This method has a error parameter, using which you can know the XMPP error code and error description and alert the user about this error.
Here is the Objective C code for didNotRegister delegate method.
You can alert the user based on the error code as shown in the above code.
Feel free to comment in case of any queries or concerns.