【问题标题】:need XMPP Framework需要 XMPP 框架
【发布时间】:2013-02-14 09:57:49
【问题描述】:

我正在设置 ejabberd,我成功配置了服务器,但是在客户端我们需要 XMPP 框架,

我用谷歌搜索了以下链接

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

我下载了 robbiehanson / XMPPFramework 但它抛出了错误,并且一些链接给了我 404 错误(他们已删除)

我从这个链接 (https://github.com/funkyboy/Building-a-Jabber-client-for-iOS) 下载了 jabber 客户端,但是 xmpp 框架文件从应用程序中抛出错误(那些已经被删除)

我得到了一个 iPhoneXMPP 示例,但它抛出错误“无法连接到服务器。检查 xmppStream.hostName”我在 willSecureWithSettings 方法中给出了我的主机名

疑问:

1)请指导我下载正确的 XMPP 框架,没有错误

2)如何配置ejabber客户端?

请指导我

提前非常感谢

【问题讨论】:

  • 2 年前,我下载了它的基本版本。不是更新的和完成的 POC 推送通知。在那里我用它配置了 gtalk,后来 poc 被合并到雷达中。现在我没有任何源代码可以帮助你,但我想帮助你......
  • 好的.. 谢谢@AnoopVaidya
  • @Babul我已将 XMPP 框架及其所有依赖项添加到我的 iPhone 聊天应用程序中,并且它没有给出任何错误(成功构建)。现在你能帮我吗,现在添加 XMPP 框架后我需要在我的应用程序中做什么......?谢谢

标签: iphone ios objective-c xmppframework


【解决方案1】:

【讨论】:

    【解决方案2】:

    大约 6 个月前,我从以下链接下载了 robbiehanson/XMPPFramework:https://github.com/robbiehanson/XMPPFramework。我按照Getting Started 部分中提到的步骤进行操作。它没有抛出任何错误。只需尝试按照这些步骤为您的应用程序设置 xmppframework。

    在示例应用程序中,我找到了启动应用程序时调用的函数setupStream()。在这个函数中,我正在创建一个 xmppStream 并激活我的应用程序中需要的不同模块。例如

    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;
    

    设置流后,您需要像这样进行身份验证:

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

    这个函数会被框架调用并在这里传递密码:

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

    现在如果用户通过了身份验证,就会调用这个函数:

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

    goOnline 会将用户的状态发送到服务器:

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

    现在您可以发送/接收消息/状态等。

    【讨论】:

    • @Akash我已将 XMPP 框架及其所有依赖项添加到我的 iPhone 聊天应用程序中,并且它没有给出任何错误(成功构建)。现在你能帮我吗,现在添加 XMPP 框架后我需要在我的应用程序中做什么......?谢谢
    • 嘿兄弟,我的代码中的模块在 git 中不可用,这些模块显示错误,而且现在 xmppstream 中没有“连接”方法..我的代码没有错误,但是,它没有连接到服务器。我有一个服务器托管在那里...请尽快帮助我..
    猜你喜欢
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 2016-10-03
    • 2015-06-05
    • 2014-05-13
    • 2012-06-08
    相关资源
    最近更新 更多