gpt4 book ai didi

swift - 在 Swift 中从 XMPP 获取名册

转载 作者:搜寻专家 更新时间:2023-10-31 23:03:01 29 4
gpt4 key购买 nike

您好,我是 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 获取花名册列表。我在花名册类中找到了一个委托(delegate)方法

(void)xmppRosterDidEndPopulating:(XMPPRoster *)sender;

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

最佳答案

最后我通过像这样设置委托(delegate)得到了 asnwer

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

}

关于swift - 在 Swift 中从 XMPP 获取名册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31175325/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com