简体   繁体   中英

unable to register new user from ejabbered xmpp in objective c

In SignupViewController

if (![[[self appdelegate] xmppStream] isConnected]) {
            [[self appdelegate] setupStream];
            [[self appdelegate]connect] && [[self appdelegate].xmppStream supportsInBandRegistration];

        } else {
            [[self  appdelegate] registerWithElements];
        }

In AppDelegate.m

- (void)registerWithElements {
    NSError *error = nil;
    NSMutableArray *elements = [NSMutableArray array];
    [elements addObject:[NSXMLElement elementWithName:@"username" stringValue:[UserDefaultsManager getUsername]]];
    [elements addObject:[NSXMLElement elementWithName:@"password" stringValue:[UserDefaultsManager getPassword]]];
    [elements addObject:[NSXMLElement elementWithName:@"email" stringValue:[UserDefaultsManager getUsername]]];

    [[self xmppStream] registerWithElements:elements error:&error];
}

It always goes in didNotRegister method. Please provide a suitable solution to register successfully.

Hope this will help you :

- (AppDelegate *)appDelegate
{
    return (AppDelegate *)[[UIApplication sharedApplication]delegate];
}

- (XMPPStream *)xmppStream {
    return [[self appDelegate] xmppStream];
}

-(void)registerUser {
    NSString *myJID = userName;
    NSString *myPassword = password;

    //
    // If you don't want to use the Settings view to set the JID,
    // uncomment the section below to hard code a JID and password.
    //
    //   myJID = @"raj@h.local";
    //   myPassword = @"123";

    //if (myJID == nil || myPassword == nil) {
    //    return ;
    //}

    [_xmppStreamM setMyJID:[XMPPJID jidWithString:myJID]];
    //password = myPassword;

    NSError *error = nil;

    if (![_xmppStreamM connectWithTimeout:XMPPStreamTimeoutNone error:&error])
        if (myJID == nil || myPassword == nil) {
            return ;;
        }

    [_xmppStreamM setMyJID:[XMPPJID jidWithString:myJID]];
    //_password = myPassword;

    //NSError *error = nil;
    if (![_xmppStreamM connectWithTimeout:XMPPStreamTimeoutNone error:&error])
        [[[self appDelegate] xmppStream] connectWithTimeout:XMPPStreamTimeoutNone error:nil];

    //_userName = self.userName.text;
    //  NSString *password = self.password.text;
    //    NSString *name =@"raj";
    //
    //
    //    NSString *email=@"raj@gmail.com";


    NSMutableArray *elements = [NSMutableArray array];

    [elements addObject:[NSXMLElement elementWithName:@"username" stringValue:@"username"]];
    [elements addObject:[NSXMLElement elementWithName:@"password" stringValue:@"password"]];

    [[[self appDelegate] xmppStream] registerWithElements:elements error:nil];
    NSLog(@"Register ====%@",[[self appDelegate] xmppStream]);
    NSLog(@"Register ====%@",elements);
}

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