2014-03-26 90 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

我通過確保連接來獲得輸出 –