iosobjective-cxmppframeworkfacebook-chat

How to Configure XMPP Facebook chat in iOS application


I am developing an iOS application which uses the Facebook chat feature.

(I am using the XMPPFramework by Robbie Hanson).

https://github.com/robbiehanson/XMPPFramework

In connect method i have given my user name and password

- (BOOL)connect
{
    if (![xmppStream isDisconnected]) {
        return YES;
    }

    NSString *myJID = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyJID];
    NSString *myPassword = [[NSUserDefaults standardUserDefaults] stringForKey:kXMPPmyPassword];

    //
    // 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 = @"example@facebook.com";
     myPassword = @"Mypassword";

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

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

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

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

        return NO;
    }

in up stream method i have given my host name and port number

- (void)setupStream
{
    NSAssert(xmppStream == nil, @"Method setupStream invoked multiple times");


    xmppStream = [[XMPPStream alloc] init];

    #if !TARGET_IPHONE_SIMULATOR
    {


        xmppStream.enableBackgroundingOnSocket = YES;
    }
    #endif



    xmppReconnect = [[XMPPReconnect alloc] init];



    xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];


    xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];

    xmppRoster.autoFetchRoster = YES;
    xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;



    xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
    xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];

    xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];


    xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
    xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:xmppCapabilitiesStorage];

    xmppCapabilities.autoFetchHashedCapabilities = YES;
    xmppCapabilities.autoFetchNonHashedCapabilities = NO;

    // Activate xmpp modules

    [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_main_queue()];
    [xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];


    [xmppStream setHostName:@"chat.facebook.com"];
    [xmppStream setHostPort:5222];


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

Is there any steps that I have missed out? I have no idea how to proceed further. Help me if any one know the solution. Please help me out Thanks in advance.


Solution

  • Try securing the connection using:

    [xmppStream secureConnection:(NSError *)];
    

    in the

     - (void)xmppStreamDidConnect:(XMPPStream *)sender; 
    

    delegate method.

    Hope it helps.