在Swift中从XMPP获取名单

时间:2015-07-02 03:54:26

标签: swift xmpp

您好我是iPhone开发的新手,我对Objective c一无所知。我正在使用swift开发一个应用程序。我在我的项目中添加了XMPP框架,并且XMPP连接成功。我使用以下代码来设置我的连接

func setupStream () {

        xmppStream = XMPPStream()
        xmppStream!.addDelegate(self, delegateQueue: dispatch_get_main_queue())
        xmppReconnect = XMPPReconnect();
        xmppRosterStorage = XMPPRosterCoreDataStorage();
        xmppRoster = XMPPRoster(rosterStorage: xmppRosterStorage);



        xmppvCardStorage = XMPPvCardCoreDataStorage.sharedInstance();
        xmppvCardTempModule = XMPPvCardTempModule(withvCardStorage:xmppvCardStorage);

        xmppvCardAvatarModule = XMPPvCardAvatarModule(withvCardTempModule:xmppvCardTempModule);

        xmppCapabilitiesStorage = XMPPCapabilitiesCoreDataStorage.sharedInstance();
        xmppCapabilities = XMPPCapabilities(capabilitiesStorage: xmppCapabilitiesStorage);

        // SET UP ALL XMPP MODULES
        xmppRoster!.autoFetchRoster = true;
        xmppRoster!.autoAcceptKnownPresenceSubscriptionRequests = true;

        xmppCapabilities!.autoFetchHashedCapabilities = true;
        xmppCapabilities!.autoFetchNonHashedCapabilities = true;

        xmppMessageArchivingStorage = XMPPMessageArchivingCoreDataStorage.sharedInstance();
        xmppMessageArchivingModule = XMPPMessageArchiving(messageArchivingStorage: xmppMessageArchivingStorage);
        xmppMessageArchivingModule!.clientSideMessageArchivingOnly = true;


        // Activate xmpp modules
        xmppReconnect!.activate(xmppStream);
        xmppRoster!.activate(xmppStream);
        xmppvCardTempModule!.activate(xmppStream);
        xmppvCardAvatarModule!.activate(xmppStream);
        xmppCapabilities!.activate(xmppStream);
        xmppMessageArchivingModule!.activate(xmppStream);


        xmppRoster!.addDelegate(self, delegateQueue:dispatch_get_main_queue());
        xmppMessageArchivingModule!.addDelegate(self, delegateQueue:dispatch_get_main_queue());


          }

以下方法工作正常

func xmppStream(sender: XMPPStream?, didReceiveMessage: XMPPMessage?) {
}


func xmppStream(sender: XMPPStream?, didReceivePresence: XMPPPresence?) {
}

现在我想从XMPP获取名单。我在名册类中找到了一个委托方法

(void)xmppRosterDidEndPopulating:(XMPPRoster *)sender;

但是如何在Swift类中使用它。请帮帮我......

1 个答案:

答案 0 :(得分:1)

最后我通过像这样设置委托来获得asnwer

func xmppRosterDidEndPopulating(sender: XMPPRoster?){
        var jidList = xmppRosterStorage?.jidsForXMPPStream(xmppStream)
        println("List=\(jidList)")

    }