gpt4 book ai didi

swift - xmppframework 的 didReceive 存在无法正常工作

转载 作者:搜寻专家 更新时间:2023-11-01 06:26:38 24 4
gpt4 key购买 nike

我正在使用 func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) 来管理在线离线状态。这个功能对于一对一用户来说工作正常,但它不能在多个用户上正常工作用户。

例如,我有 3 个用户 A、B 和 C,现在情况是在线离线状态对于 A 到 B 和 B 到 A 工作正常,如 func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) 函数调用得很好。但如果 C 用户检查 A 或 B 的状态,则 func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) 不会被调用。

我无法理解问题所在。这是我的代码:

func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) {
let presenceType = presence.type
let myUsername = sender.myJID?.user

print("myusername \(myUsername)")

if let usr = presence.from?.user {

print("didReceive :- \(presenceType)")
print("didReceive usr :- \(usr)")

if usr != myUsername {
if presenceType == "available" {
let dict: NSDictionary = ["presenceType":"1",
"user_id":usr]
if !APP_DELEGATE.arrPresentUser.contains(dict) {
APP_DELEGATE.arrPresentUser.add(dict)
}
} else {
let pred : NSPredicate = NSPredicate(format: "user_id = %@", usr)
let approvalRequestArray = APP_DELEGATE.arrPresentUser.filtered(using: pred) as NSArray
if approvalRequestArray.count > 0 {
let dict = approvalRequestArray.object(at: 0) as! NSDictionary
APP_DELEGATE.arrPresentUser.remove(dict)
}
}
NotificationCenter.default.post(name: Notification.Name("ReceivedUserStatus"), object: nil)
}
}
}

注意:我也尝试过使用@objc(@objc func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) )

最佳答案

如果你想检查特定用户的存在,使用这个。

  let query = XMLElement(name: "query", xmlns: "jabber:iq:last")
let iq = XMPPIQ(type: "get", to: "User's JID here", elementID: xmppStream.generateUUID, child: query)
self.xmppStream.send(iq)

获取委托(delegate)方法中的存在。

  func xmppStream(_ sender: XMPPStream, didReceive iq: XMPPIQ) -> Bool {
if iq.isResultIQ {
print(iq.from?.user)
print(iq.lastActivitySeconds())
}
}

关于swift - xmppframework 的 didReceive 存在无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53498461/

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