Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Methods for new user registration xmpp framework iOS

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.

like image 764
obaid Avatar asked Apr 21 '12 08:04

obaid


2 Answers

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];
}
like image 161
Karun Avatar answered Nov 08 '22 00:11

Karun


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
like image 30
Rohit Mandiwal Avatar answered Nov 07 '22 23:11

Rohit Mandiwal