Anshu
Anshu

Reputation: 521

XMPP: Registration gives error in iOS

Hi I a using the below code for registration.

After xmppStream has been connected then I call this code inside didNotAuthenticate method:

- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error
{

    NSString *jidStr = @"mohit@localhost";
    NSString password = @"mohit";
    XMPPJID *jid = [XMPPJID jidWithString:jidStr];
    [self  xmppStream].myJID =jid;

    if (self.xmppStream.supportsInBandRegistration) {
        if (![self.xmppStream registerWithPassword:password error:&error]) {
            NSLog(@"Registration error: %@", error);
        }
        else{
            NSLog(@"Registration on progress");
        }
    } 
    else {
        NSLog(@"Inband registration is not supported");
    }
}

in Console it prints the "Registration on progress" but in the below delegate method

- (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];
    NSLog(@"%@",regError);
}

It gives error:

<iq xmlns="jabber:client" from="localhost" type="error"><query xmlns="jabber:iq:register">
<username>mohit</username><password>mohit</password></query><error code="403" type="auth">
<forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

I am using the ejabberd server. Please help me on this.

Upvotes: 3

Views: 1133

Answers (1)

Teena nath Paul
Teena nath Paul

Reputation: 2259

Following steps worked for me

  1. Go to your Ejabbered admin home page and login with admin credentials. ("http://YourServerHostName:5280/admin/")

  2. Click on "Access Rules" from left side menu.

  3. In the textfield at the bottom the page, paste the following access rule and click "Add New".

    {access, register_from, [{allow, all}]}

    This should eliminate the 403 forbidden error.

  4. After forbidden error is resolved one more error may arrive that is "Users are not allowed to register accounts so quickly". For this again copy and paste the following access rule in the same textfield and click "Add New".

    {access, register, [{all, allow}, {registration_timeout, infinity}]}

    This should eliminate the above error.

Upvotes: 4

Related Questions