2
votes

I am working on ejabberd setup, i configured the server successfully, But in the client side we need XMPP Framework for this,

I Googled i got the following links

http://deusty.blogspot.in/2008/08/xmppframework-on-iphone.html

http://iphone4developer.blogspot.in/2011/07/how-to-add-xmpp-in-your-ios-project.html

I downloaded the robbiehanson / XMPPFramework but it throws errors, and some links gives me 404 error(they removed)

I downloaded the jabber client from this link (https://github.com/funkyboy/Building-a-Jabber-client-for-iOS) but the xmpp framework files throws errors(those are already deleted) from the app

I got one sample that is iPhoneXMPP sample but it throws error that is "Unable to connect to server. Check xmppStream.hostName" i given my host name in willSecureWithSettings method

Doubts:

1)Please Guide me to download the proper XMPP Framework with out errors

2)How to Configure ejabber client side?

Please guide me

Thanks a lot in advance

2
2 years ago, i downloaded its basic version. not the updated one and done one POC Push-Notification. there I configured gtalk with it, and later that poc was incorporated into radar. Now I dont have any sourcecode to help you, but I would like to help you...Anoop Vaidya
ok.. Thank u @AnoopVaidyaBabul
@BabulI have added XMPP framework with all their dependencies into my iPhone chat app, and it is not giving any error (built successfully). Now can you pls help me, now what things i need to do in my app after adding XMPP framework..?ThanksAnand Gautam

2 Answers

5
votes

I downloaded the robbiehanson/XMPPFramework around 6 months back from this link: https://github.com/robbiehanson/XMPPFramework . I followed the steps that are mentioned in Getting Started section. It didn't throw any error. Just try to follow these steps to setup the xmppframework with your application.

In sample app, I found the function setupStream() that I am calling when I start my application. In this function I am creating an xmppStream and activating different modules that are needed in my application. e.g

xmppStream = [[XMPPStream alloc] init];

    // Activate xmpp modules after creating them

    [xmppReconnect         activate:xmppStream];
    [xmppRoster            activate:xmppStream];
    [xmppvCardTempModule   activate:xmppStream];
    [xmppvCardAvatarModule activate:xmppStream];
    [xmppCapabilities      activate:xmppStream];

    // Add ourself as a delegate to anything we may be interested in

    [xmppStream addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];


[xmppStream setHostName:XMPPHOST];
[xmppStream setHostPort:5222];

// You may need to alter these settings depending on the server you're connecting to
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;

After setting the stream, you need to do authentication like this:

- (BOOL)connect:(NSString *)myJID    //username registered with server
{
    if (![xmppStream isDisconnected]) {
        return YES;
    }

    if (myJID == nil) {
        return NO;
    }

    [xmppStream setMyJID:[XMPPJID jidWithString:myJID]];

    NSError *error = nil;
    if (![xmppStream connect:&error])
    {        
        if(DEBUG)
        {
            NSLog(@"ERROR: Not connected to XMPP Server");
        }
        DDLogError(@"Error connecting: %@", error);
        return NO;
    }
    return YES;
}

This function will be called by the framework and pass the password here:

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    if(sender == xmppStream)
    {
        //DDLogVerbose(@"In xmppStream: %@: %@", THIS_FILE, THIS_METHOD);

        isXmppConnected = YES;

        NSError *error = nil;

        if (![[self xmppStream] authenticateWithPassword:password error:&error])
        {
            DDLogError(@"Error authenticating: %@", error);
        }
    }    
}

Now if user is authenticated, this function will be called:

- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
    if(sender == xmppStream)
    {
        [self goOnline];
    }
}

goOnline will send user's presence to server:

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

Now you can send/receive the message/presence etc.