didReceiveInvitation() 未在 XMPPFramework 中调用,Swift 2
didReceiveInvitation() is not being called in XMPPFramework and Swift 2
我正在创建像 Whatsapp.
这样的聊天应用程序
我已经成功编写了文本聊天、图像、音频、视频传输的功能。现在我正在创建多用户聊天。经过长时间的研发,我问这个问题。请告诉我我的代码做错了什么。我已经遵循了所有这些教程,但不是运气
https://github.com/robbiehanson/XMPPFramework/issues/640
MUC How-to with XMPPFramework
Accepting chatroom invitation
好的 下面是我的代码
1.成功设置 STREAM 后,我在 goOnline Method
中为邀请设置了 XMPPMUC 委托
private func goOnline() {
let presence = XMPPPresence()
let domain = xmppStream.myJID.domain
if domain == "gmail.com" || domain == "gtalk.com" || domain == "talk.google.com"
// || domain == "chat.alqatech.com"
{
let priority = DDXMLElement.elementWithName("priority", stringValue: "24") as! DDXMLElement
presence.addChild(priority)
}
xmppMUC = XMPPMUC(dispatchQueue: dispatch_get_main_queue())
xmppMUC!.activate(self.xmppStream)
xmppMUC!.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppStream.sendElement(presence)
}
2。创建群组
func createGroupChat(members:[String],groupName:String){
membersToInvite = members
xmppRoomMemoryStorage = XMPPRoomMemoryStorage()
let xmppJid = XMPPJID.jidWithString("\(groupName)@conference.chat.xxxxxx.com")
let xmppRoom = XMPPRoom.init(roomStorage: xmppRoomMemoryStorage, jid: xmppJid)
xmppRoom.activate(xmppStream)
xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppRoom.joinRoomUsingNickname(xmppStream.myJID.user, history: nil)
}
3。群组创建成功
func xmppRoomDidCreate(sender: XMPPRoom!) {
print(sender)
}
4。 xmppRoomDidJoin 调用成功然后在这里我邀请用户
func xmppRoomDidJoin(sender: XMPPRoom!) {
sender.fetchConfigurationForm()
for JID in membersToInvite! {
sender.editRoomPrivileges([XMPPRoom.itemWithAffiliation("member", jid: XMPPJID.jidWithString(JID))])
sender.inviteUser(XMPPJID.jidWithString(JID), withMessage: "THIS IS GROUP MESSAGE")
}
}
5。 didFetchConfigurationForm 调用成功
func xmppRoom(sender: XMPPRoom!, didFetchConfigurationForm configForm: DDXMLElement!)
{
let newConfig: DDXMLElement = configForm.copy() as! DDXMLElement
let fields: [AnyObject] = newConfig.elementsForName("field")
for field in fields {
let vars: String = field.attributeStringValueForName("var")
// Make Room Persistent
if (vars == "muc#roomconfig_persistentroom") {
field.removeChildAtIndex(0)
field.addChild(DDXMLElement(name: "value", stringValue : "1"))
}
}
sender.configureRoomUsingOptions(newConfig)
}
6. didReceiveInvitation 它没有被调用。
func xmppMUC(sender: XMPPMUC!, roomJID: XMPPJID!, didReceiveInvitation message: XMPPMessage!) {
print(roomJID)
xmppRoomMemoryStorage = XMPPRoomMemoryStorage()
let xmppRoom = XMPPRoom.init(roomStorage: xmppRoomMemoryStorage, jid: roomJID)
xmppRoom.activate(xmppStream)
xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppRoom.joinRoomUsingNickname(xmppStream.myJID.user, history: nil)
}
如果你在文件XMPPMUC.m第317行设置断点
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
向您的用户发送邀请时是否调用该方法?如果是,继续调试,检查382行是否正在执行。
那一行是这样的:
[multicastDelegate xmppMUC:self roomJID:roomJID didReceiveInvitation:message];
问题出在这段代码中。实际上,每次我邀请任何用户时,我都会发送裸 ID。
func xmppRoomDidJoin(sender: XMPPRoom!) {
sender.fetchConfigurationForm()
for JID in membersToInvite! {
sender.editRoomPrivileges([XMPPRoom.itemWithAffiliation("member", jid: XMPPJID.jidWithString(JID))])
sender.inviteUser(XMPPJID.jidWithString(JID), withMessage: "THIS IS GROUP MESSAGE")
}
}
但要邀请任何用户,您必须使用完整 ID。
对于那些不知道的人
BareID = username@domain
全名 = 用户名@domain/resource
解决这个问题
我在整个应用程序的 JID 中对 resource = APPNAME 进行了硬编码。
我正在创建像 Whatsapp.
这样的聊天应用程序
我已经成功编写了文本聊天、图像、音频、视频传输的功能。现在我正在创建多用户聊天。经过长时间的研发,我问这个问题。请告诉我我的代码做错了什么。我已经遵循了所有这些教程,但不是运气
https://github.com/robbiehanson/XMPPFramework/issues/640
MUC How-to with XMPPFramework
Accepting chatroom invitation
好的 下面是我的代码
1.成功设置 STREAM 后,我在 goOnline Method
中为邀请设置了 XMPPMUC 委托private func goOnline() {
let presence = XMPPPresence()
let domain = xmppStream.myJID.domain
if domain == "gmail.com" || domain == "gtalk.com" || domain == "talk.google.com"
// || domain == "chat.alqatech.com"
{
let priority = DDXMLElement.elementWithName("priority", stringValue: "24") as! DDXMLElement
presence.addChild(priority)
}
xmppMUC = XMPPMUC(dispatchQueue: dispatch_get_main_queue())
xmppMUC!.activate(self.xmppStream)
xmppMUC!.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppStream.sendElement(presence)
}
2。创建群组
func createGroupChat(members:[String],groupName:String){
membersToInvite = members
xmppRoomMemoryStorage = XMPPRoomMemoryStorage()
let xmppJid = XMPPJID.jidWithString("\(groupName)@conference.chat.xxxxxx.com")
let xmppRoom = XMPPRoom.init(roomStorage: xmppRoomMemoryStorage, jid: xmppJid)
xmppRoom.activate(xmppStream)
xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppRoom.joinRoomUsingNickname(xmppStream.myJID.user, history: nil)
}
3。群组创建成功
func xmppRoomDidCreate(sender: XMPPRoom!) {
print(sender)
}
4。 xmppRoomDidJoin 调用成功然后在这里我邀请用户
func xmppRoomDidJoin(sender: XMPPRoom!) {
sender.fetchConfigurationForm()
for JID in membersToInvite! {
sender.editRoomPrivileges([XMPPRoom.itemWithAffiliation("member", jid: XMPPJID.jidWithString(JID))])
sender.inviteUser(XMPPJID.jidWithString(JID), withMessage: "THIS IS GROUP MESSAGE")
}
}
5。 didFetchConfigurationForm 调用成功
func xmppRoom(sender: XMPPRoom!, didFetchConfigurationForm configForm: DDXMLElement!)
{
let newConfig: DDXMLElement = configForm.copy() as! DDXMLElement
let fields: [AnyObject] = newConfig.elementsForName("field")
for field in fields {
let vars: String = field.attributeStringValueForName("var")
// Make Room Persistent
if (vars == "muc#roomconfig_persistentroom") {
field.removeChildAtIndex(0)
field.addChild(DDXMLElement(name: "value", stringValue : "1"))
}
}
sender.configureRoomUsingOptions(newConfig)
}
6. didReceiveInvitation 它没有被调用。
func xmppMUC(sender: XMPPMUC!, roomJID: XMPPJID!, didReceiveInvitation message: XMPPMessage!) {
print(roomJID)
xmppRoomMemoryStorage = XMPPRoomMemoryStorage()
let xmppRoom = XMPPRoom.init(roomStorage: xmppRoomMemoryStorage, jid: roomJID)
xmppRoom.activate(xmppStream)
xmppRoom.addDelegate(self, delegateQueue: dispatch_get_main_queue())
xmppRoom.joinRoomUsingNickname(xmppStream.myJID.user, history: nil)
}
如果你在文件XMPPMUC.m第317行设置断点
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
向您的用户发送邀请时是否调用该方法?如果是,继续调试,检查382行是否正在执行。
那一行是这样的:
[multicastDelegate xmppMUC:self roomJID:roomJID didReceiveInvitation:message];
问题出在这段代码中。实际上,每次我邀请任何用户时,我都会发送裸 ID。
func xmppRoomDidJoin(sender: XMPPRoom!) {
sender.fetchConfigurationForm()
for JID in membersToInvite! {
sender.editRoomPrivileges([XMPPRoom.itemWithAffiliation("member", jid: XMPPJID.jidWithString(JID))])
sender.inviteUser(XMPPJID.jidWithString(JID), withMessage: "THIS IS GROUP MESSAGE")
}
}
但要邀请任何用户,您必须使用完整 ID。
对于那些不知道的人
BareID = username@domain 全名 = 用户名@domain/resource
解决这个问题
我在整个应用程序的 JID 中对 resource = APPNAME 进行了硬编码。