简体   繁体   中英

Use User Service in Openfire to Register new user via xmpp framework for iOS

I can see now the users manually created in my openfire server, i am working with a book to achieve this but, there is a way the programmer register a user via http using the openfire and the user service plugin. I want to know how to register a new user with this feature and if i can check if the user already exists on the openfire server with my iOS application. How can i get the http link of my openfire to achieve a registration or is there another way? i read that for custom registration it would be good to create a webservice but i know very little about webservices so please anyone can help, Thanks.

You need to register a user by creating an NSXMLElement and pass it to the xmppstream to register new user.Make sure you have xmppstream object so that you are able to fire your queries to server and get the required output.

NSMutableArray *elements = [NSMutableArray array];
[elements addObject:[NSXMLElement elementWithName:@"username" stringValue:@"abc"]];
[elements addObject:[NSXMLElement elementWithName:@"password" stringValue:@"xyz"]];
[elements addObject:[NSXMLElement elementWithName:@"name" stringValue:@"abc"]];
[elements addObject:[NSXMLElement elementWithName:@"email" stringValue:@"abc@xyz.com"]];
[self.xmppStream registerWithElements:elements error:nil];
[self connect];

This will register a new user or in-case the user already exists on your server it gives you an error in received iq.

This solution HAS WORKED for me. A more organised approch

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM