【问题标题】:XMPP Connection with server and configure Client side in iOSXMPP 与服务器的连接并在 iOS 中配置客户端
【发布时间】:2016-05-02 12:48:05
【问题描述】:

我正在使用服务器连接到 XMPP 流,但即使用户名、密码错误,连接也始终成功。无法理解为什么会发生这种情况。 我想在我的应用程序中配置客户端,并希望将我的应用程序与 XMPP 服务器连接起来。帮助将不胜感激。以下是我的代码:

    import UIKit
    import XMPPFramework
    protocol ChatDelegate {
        func buddyWentOnline(name: String)
        func buddyWentOffline(name: String)
        func didDisconnect()
    }
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate, XMPPStreamDelegate, XMPPRosterDelegate{
        var window: UIWindow?
        var delegate:ChatDelegate! = nil
        var xmppStream = XMPPStream()
        let xmppRosterStorage = XMPPRosterCoreDataStorage()
        var xmppRoster: XMPPRoster
        override init() {
            xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage)
        }
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:
            [NSObject: AnyObject]?) -> Bool {
                //setupStream()
                self.xmppStream = XMPPStream()
                self.xmppStream.addDelegate(self, delegateQueue: dispatch_get_main_queue())
                self.xmppStream.hostName = "****softs-mbp-9"
                self.xmppStream.hostPort = 5222
                self.connect()
                return true
        }
func connect() -> Bool {
            if !xmppStream.isConnected() {
                let jabberID = "admin@****softs-mbp-9"
                let myPassword = "**********"

                if !xmppStream.isDisconnected() {
                    return true
                }
    //            if jabberID == nil && myPassword == nil {
    //                return false
    //            }

                xmppStream.myJID = XMPPJID.jidWithString(jabberID)

                do {
                    try xmppStream.connectWithTimeout(XMPPStreamTimeoutNone)
                    print("Connection success")
                    return true
                } catch {
                    print("Something went wrong!")
                    return false
                }
            } else {
                return true
            }
        }

        func disconnect() {
            goOffline()
            xmppStream.disconnect()
        }
    }

【问题讨论】:

    标签: ios swift server xmppframework


    【解决方案1】:

    您是否将用户名设置为 admin@****softs-mbp-9?

    【讨论】:

    • 应该是评论:)
    • 让 jabberID = "admin@****softs-mbp-9" 它是一个用户名
    • 但是问题已解决。主机名和端口连接成功。但用户验证是通过用户认证回调。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    • 2018-02-27
    • 2013-08-27
    • 2014-11-04
    相关资源
    最近更新 更多