2014-03-26 96 views
2

我正在开发使用Facebook聊天功能的iOS应用程序。如何在iOS应用程序中配置XMPP Facebook聊天

(我正在使用Robbie Hanson的XMPPFramework)。

https://github.com/robbiehanson/XMPPFramework

在连接方法我已经给我的用户名和密码

- (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 = @"[email protected]"; 
    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; 
    } 

多达流的方法,我已经给我的主机名和端口号

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

有什么我错过了哪些步骤?我不知道如何继续下去。如果有人知道解决方案,请帮助我。请帮助我 在此先感谢。

+0

正如我看到你只改变了图书馆的示例项目。您在设置这些参数时是否能够看到您的聊天朋友? – ismailgulek

+0

即使我的朋友列表没有显示在应用程序中。善意帮助我继续前进任何好的教程教程。 –

+0

当您在示例应用程序的“设置”页面中设置好您的朋友列表时,应显示它们。尽量不要设置hostName。您需要开始使用XMPP文档:'http:// xmpp.org/xmpp-protocols/xmpp-core /' – ismailgulek

回答

1

尝试确保使用连接:

[xmppStream secureConnection:(NSError *)]; 

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

委托方法

希望它有帮助。

+0

我通过确保连接来获得输出 –