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

问题描述:

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

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 = "[email protected]****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() 
     } 
    } 

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

+0

它应该是一个评论:) –

+0

是的,但我不能评论他的帖子,因为我没有50代表.... – Matak

+0

让jabberID =“管理员@ ****软件-mbb-9”其用户名为 – Mughees