didReceiveInvitation()不在XMPPFramework和Swift 2中调用
我正在创build像Whatsapp聊天应用程序。
我已经成功编写了文字聊天,图像,audio,video传输的function。 现在我正在创build多用户聊天。 经过长时间的研发,我正在问这个问题。 请告诉我在我的代码中我做错了什么。 我遵循所有这些教程,但不是运气
https://github.com/robbiehanson/XMPPFramework/issues/640
MUC如何与XMPPFramework
接受聊天室邀请
好的,下面是我的代码
1.成功设置STREAM后,我在GoOnline方法中设置了邀请的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.创build一个组
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.组创build成功
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
当邀请被发送给你的用户时,该方法被调用吗? 如果是这样,继续debugging,并检查是否正在执行第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 =用户名@域FullID =用户名@域/资源
解决这个问题
我在整个应用程序的JID中的任何地方硬编码资源= APPNAME。