XMPP与服务器连接并在iOS中配置客户端

时间:2016-05-02 12:48:05

标签: ios swift server xmppframework

我正在使用服务器连接到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()
        }
    }

1 个答案:

答案 0 :(得分:0)

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