无法从目标 c 中的 ejabbered xmpp 注册新用户

Posted

技术标签:

【中文标题】无法从目标 c 中的 ejabbered xmpp 注册新用户【英文标题】:unable to register new user from ejabbered xmpp in objective c 【发布时间】:2015-05-25 05:34:16 【问题描述】:

在 SignupViewController 中

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

         else 
            [[self  appdelegate] registerWithElements];
        

在 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];

它总是在 didNotRegister 方法中。请提供合适的解决方案以成功注册。

【问题讨论】:

【参考方案1】:

希望对您有所帮助:

- (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);

【讨论】:

没有。我已经通过从应用程序委托调用它来完成上述相同的事情。所以你能解释一下为什么我需要写这个吗? 我总是面临这个问题错误:- sdg@bhuvan-mac-2.localsdgdsgsdg@bhuvan-mac-2.local @Bhu 你不明白哪一部分? 我已经注册成功并且通过断点已经验证 registerWithElements 是返回 YES ,我主要关心的是我遇到的错误。错误的请求错误。 @Bhu.ONEBhatt 你在你的服务器上检查过用户是否注册了吗?

以上是关于无法从目标 c 中的 ejabbered xmpp 注册新用户的主要内容,如果未能解决你的问题,请参考以下文章

如何在目标c中通过ios中的XMPPFramework连接XMPP服务器

在 xmpp 中创建一个 pubsub 节点

通过 Mule ESB CE 连接 Ejabbered

使用f***g php注销ejabbered用户

无法将 agsXmpp 客户端连接到 eJabberd 服务器

无法打开 ejabbered Web 仪表板 localhost:5280