6
votes

I am developing one simple chat application using XMPPFramework from robbiehanson. I have installed eJabberd server in my system and created some users. I set hostname = "localhost" and tried to login with that user credentials. It is successfully logged in. When I change the hostname ie hostname="talk.google.com". I cant able to login. I got "Sign-in attempt prevented" mail and

<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized></not-authorized></failure>

FYI,

- (BOOL)connectWithUsername:(NSString*)username WithPassword:(NSString*)pwd
{
    if (![xmppStream isDisconnected]) {
        return YES;
    }

   // NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyJID];
    //NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword];
    NSString* myJID=username;
    NSString* myPassword=pwd;
    //
    // 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.
    //
    // Replace me with the proper JID and password:
    //  myJID = @"[email protected]/xmppframework";
    //  myPassword = @"";

    if (myJID == nil || myPassword == nil) {
        NSLog(@"JID and password must be set before connecting!");

        return NO;
    }

    [xmppStream setMyJID:[XMPPJID jidWithString:myJID]];
    password = myPassword;

    NSError *error = nil;
    if (![xmppStream connectWithTimeout:100 error:&error])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error connecting"
                                                             message:@"See console for error details."
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];

        NSLog(@"Error connecting: %@", error);

        return NO;
    }


    [self goOnline];

    return YES;
}

Am I need to register app in Google Developer Console? Kindly provide me the solution to integrate Gmail account in the XMPPFramework.

1
@the_UB I couldnt seeSridhar
click on text check itBista

1 Answers

0
votes

Are you sure you have set your JID and hostname correctly ?

There are some instructions in XMPPStream.h file just above hostname property.

You should also know that configurations for Google servers on XMPP differs a bit, Make sure required configurations are done inside XMPPXOAuth2Google.m file and also inside goOnline method on delegate.

Some default changes are done by XMPPFramework :

- (void)goOnline
{
    XMPPPresence *presence = [XMPPPresence presence]; // type="available" is implicit

    NSString *domain = [xmppStream.myJID domain];

    //Google set their presence priority to 24, so we do the same to be compatible.

    if([domain isEqualToString:@"gmail.com"] ||
       [domain isEqualToString:@"gtalk.com"] ||
       [domain isEqualToString:@"talk.google.com"])
    {
        NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" stringValue:@"24"];
        [presence addChild:priority];
    }

    [[self xmppStream] sendElement:presence];
}