XMPP ios framwoerk在swift 3中没有连接

时间:2017-09-17 14:51:43

标签: swift3 xmpp ejabberd openfire xmppframework

我使用了xmppframewotk ios。连接委托不在swift 3中工作。但socket已连接。

1 个答案:

答案 0 :(得分:0)

import XMPPFramework
inherited XMPPRosterDelegate,XMPPStreamDelegate
  1. var xmppStream:XMPPStream
  2. let xmppRosterStorage = XMPPRosterCoreDataStorage()
  3. var xmppRoster: XMPPRoster <!/ LI>

    代码:

    func connect() -> Bool {
    
        if xmppStream == nil {
            xmppStream = XMPPStream()
            xmppStream.addDelegate(self, delegateQueue: DispatchQueue.main)
        }
    
        if xmppStream.isDisconnected(){
    
            if !(xmppStream?.isDisconnected())! {
                return true
            }
            xmppStream?.myJID = XMPPJID.init(string: JABBERID)
            xmppStream?.hostName = aHost
            xmppStream?.hostPort = 5222
            xmppStream?.enableBackgroundingOnSocket = true
    
            do {
                try xmppStream?.connect(withTimeout: XMPPStreamTimeoutNone)
                print("Connection success")
                return true
            } catch {
                print("Something went wrong!")
                return false
            }
        } else {
            return true
        }
    }