为iOS设置XMPPFramework

jde*_*irm 2 xmpp objective-c ios xmppframework

我正在开发具有聊天功能的iOS应用程序.我想知道是否有任何资源来配置XMPPFramework以便将我的iOS应用程序与Openfire服务器连接.

我是XMPP协议的新手.

我目前正在学习XMPP Stream和Rosters,但我至少需要让连接工作.

请帮忙.

Kei*_*OYS 5

要开始使用,请深入了解XMPPFramework-master> Xcode> iPhoneXMPP中的示例iOS项目.

最好是在项目本身开始调整,并在继续创建自己的XMPP项目之前从中获取您的理解.

基本上将XMPP连接到OpenFire服务器,大多数配置都在AppDelegate中.

  1. 在XMPP设置中设置OpenFire服务器的详细信息:

    - (void)setupStream
    {
        ...
    
        // Specify your server's IP address
        [xmppStream setHostName:@"123.12.123.12"];
    
        // Specify your host port
        [xmppStream setHostPort:5222];
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 假设您已在OpenFire的名单中创建了联系人,请在XMPP连接方法中设置联系人的凭据:

    - (BOOL)connect
    {
        /**
         * Of course, do not hardcode in an actual implementation
         * Appending the server name at the back of user ID is necessary
         */
        myJID = @"user@openfire";
        myPassword = @"password goes here";
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 确保在app launch方法中调用connect方法:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [self connect];
    }
    
    Run Code Online (Sandbox Code Playgroud)
  4. 确保您在这里连接:

    - (void)xmppStreamDidConnect:(XMPPStream *)sender
    {
        NSLog(@"User Connected");
        // You are connected to the server at this point.            
    }
    
    Run Code Online (Sandbox Code Playgroud)
  5. 确保您在此处进行身份验证:

    - (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
    {
        NSLog(@"User Authenticated");
        /**
         * Once you've reached this point,
         * Check your server for the online users. 
         * You should now be seen as "available".
         * Cheers!
         */
    }
    
    Run Code Online (Sandbox Code Playgroud)