I have developed the XMPP Chat client for iOS and now I'm researching for how to do a new user registration from iOS itself. Can anyone help with the methods used to register a new user. As it needs to communicate with the Server and store the username and password to the server database. Please help I'm searching it from 2 days.
NSMutableArray *elements = [NSMutableArray array];
[elements addObject:[NSXMLElement elementWithName:@"username" stringValue:@"venkat"]];
[elements addObject:[NSXMLElement elementWithName:@"password" stringValue:@"dfds"]];
[elements addObject:[NSXMLElement elementWithName:@"name" stringValue:@"eref defg"]];
[elements addObject:[NSXMLElement elementWithName:@"accountType" stringValue:@"3"]];
[elements addObject:[NSXMLElement elementWithName:@"deviceToken" stringValue:@"adfg3455bhjdfsdfhhaqjdsjd635n"]];
[elements addObject:[NSXMLElement elementWithName:@"email" stringValue:@"[email protected]"]];
[[[self appDelegate] xmppStream] registerWithElements:elements error:nil];
We will know whether the registration is successful or not using the below delegates.
- (void)xmppStreamDidRegister:(XMPPStream *)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration" message:@"Registration Successful!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
- (void)xmppStream:(XMPPStream *)sender didNotRegister:(NSXMLElement *)error{
DDXMLElement *errorXML = [error elementForName:@"error"];
NSString *errorCode = [[errorXML attributeForName:@"code"] stringValue];
NSString *regError = [NSString stringWithFormat:@"ERROR :- %@",error.description];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration Failed!" message:regError delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
if([errorCode isEqualToString:@"409"]){
[alert setMessage:@"Username Already Exists!"];
}
[alert show];
}
This solution HAS WORKED for me
NSString *username = @"rohit@XMPP_SERVER_IP_HERE"; // OR [NSString stringWithFormat:@"%@@%@",username,XMPP_BASE_URL]]
NSString *password = @"SOME_PASSWORD";
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
del.xmppStream.myJID = [XMPPJID jidWithString:username];
NSLog(@"Does supports registration %ub ", );
NSLog(@"Attempting registration for username %@",del.xmppStream.myJID.bare);
if (del.xmppStream.supportsInBandRegistration) {
NSError *error = nil;
if (![del.xmppStream registerWithPassword:password error:&error])
{
NSLog(@"Oops, I forgot something: %@", error);
}else{
NSLog(@"No Error");
}
}
// You will get delegate called after registrations in either success or failure case. These delegates are in XMPPStream class
// - (void)xmppStreamDidRegister:(XMPPStream *)sender
//- (void)xmppStream:(XMPPStream *)sender didNotRegister:(NSXMLElement *)error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With