gpt4 book ai didi

swift - xmpp_messenger_ios Swift MUC swift

转载 作者:行者123 更新时间:2023-11-30 13:05:47 37 4
gpt4 key购买 nike

我正在尝试使用 xmpp_messenger_ios 和 XMPPFramework 在 iOS 上执行 MUC

这是加入房间的代码。

   func createOrJoinRoomOnXMPP(){
// location has named array of lat and long

NSLog("Creating room on XMPP")

let roomJID: XMPPJID = XMPPJID.jidWithString(self.roomID + "@conference.ip-172-31-41-100")

let roomData: XMPPRoomCoreDataStorage = XMPPRoomCoreDataStorage.sharedInstance()

let chatRoom = XMPPRoom.init(roomStorage: roomData, jid: roomJID, dispatchQueue: dispatch_get_main_queue())

chatRoom.activate(OneChat.sharedInstance.xmppStream)
chatRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())

// let history = DDXMLElement.elementWithName("history")
// // Get lst messegs of the room
// history.addAttributeWithName("maxstanzas", stringValue: "10")

chatRoom.joinRoomUsingNickname(OneChat.sharedInstance.xmppStream!.myJID.user, history: nil)
}

一旦执行此 block ,我就会在这段代码中收到错误:

扩展 OneMessage:XMPPStreamDelegate {

public func xmppStream(sender: XMPPStream, didSendMessage message: XMPPMessage) {
if let completion = OneMessage.sharedInstance.didSendMessageCompletionBlock {
completion(stream: sender, message: message)
}
//OneMessage.sharedInstance.didSendMessageCompletionBlock!(stream: sender, message: message)
}

public func xmppStream(sender: XMPPStream, didReceiveMessage message: XMPPMessage) {
let user = OneChat.sharedInstance.xmppRosterStorage.userForJID(message.from(), xmppStream: OneChat.sharedInstance.xmppStream, managedObjectContext: OneRoster.sharedInstance.managedObjectContext_roster())

if !OneChats.knownUserForJid(jidStr: user.jidStr) { // <<< ERROR LINE
OneChats.addUserToChatList(jidStr: user.jidStr)
}

if message.isChatMessageWithBody() {
OneMessage.sharedInstance.delegate?.oneStream(sender, didReceiveMessage: message, from: user)
} else {
//was composing
if let _ = message.elementForName("composing") {
OneMessage.sharedInstance.delegate?.oneStream(sender, userIsComposing: user)
}
}
}

}

fatal error :在解包可选值时意外发现 nil

我注意到,一旦连接到聊天室,它就会获取以前的消息,从而执行上面的代码。

请帮助我在 ios 上为房间聊天做一个 MUC。我已经搜索过,但没有找到任何解决方案。

谢谢

最佳答案

我通过这个临时解决方案解决了这个问题。

extension OneMessage: XMPPStreamDelegate {

public func xmppStream(sender: XMPPStream, didSendMessage message: XMPPMessage) {
if let completion = OneMessage.sharedInstance.didSendMessageCompletionBlock {
completion(stream: sender, message: message)
}
//OneMessage.sharedInstance.didSendMessageCompletionBlock!(stream: sender, message: message)
}

public func xmppStream(sender: XMPPStream, didReceiveMessage message: XMPPMessage) {
NSLog("This is blocked")

// let user = OneChat.sharedInstance.xmppRosterStorage.userForJID(message.from(), xmppStream: OneChat.sharedInstance.xmppStream, managedObjectContext: OneRoster.sharedInstance.managedObjectContext_roster())
//
// if !OneChats.knownUserForJid(jidStr: user.jidStr) {
// OneChats.addUserToChatList(jidStr: user.jidStr)
// }
//
// if message.isChatMessageWithBody() {
// OneMessage.sharedInstance.delegate?.oneStream(sender, didReceiveMessage: message, from: user)
// } else {
// //was composing
// if let _ = message.elementForName("composing") {
// OneMessage.sharedInstance.delegate?.oneStream(sender, userIsComposing: user)
// }
// }
}
}

阻止 OneMessage.swift 代码。

并在我的 ViewController 中处理传入的消息。

这不是正确的做法。但在 ProcessOne 提供对 MUC 的支持之前,这是可以完成的。

关于swift - xmpp_messenger_ios Swift MUC swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39392766/

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