在XMPPFramework和Swift 2中没有调用didReceiveInvitation() [英] didReceiveInvitation() is not being called in XMPPFramework and Swift 2

查看:188
本文介绍了在XMPPFramework和Swift 2中没有调用didReceiveInvitation()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建像 Whatsapp 这样的聊天应用程序。

我已经成功编写了文本聊天,图像,音频,视频传输功能。现在我正在创建多用户聊天。经过漫长的R& D我问这个问题。请告诉我在我的代码中我做错了什么。我已经按照所有这些教程但没有运气

I am creating chatting application like Whatsapp.
I have successfully write the functionality of Text chat, Image, Audio, Video Transfer. Now I am creating the Multi user chat. After a long R&D I am asking this question. Please tell me what I am doing wrong in my code. I have followed all these tutorials but not luck

https://github.com/robbiehanson/XMPPFramework/issues/640

MUC使用XMPPFramework的方法

接受聊天室邀请

确定以下是我的代码

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。创建一个组



2. Create a group

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。集团成功创建



3. Group Created Successfully

func xmppRoomDidCreate(sender: XMPPRoom!) {
        print(sender)
    }



4。 xmppRoomDidJoin成功调用然后在这里我邀请用户



4. xmppRoomDidJoin called successfully then here i invite users

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成功调用



5. didFetchConfigurationForm called successfully

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它没有被调用。



6. didReceiveInvitation it is not being called.

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)

    }


推荐答案

此代码存在问题。实际上,每当我邀请任何用户时,我都会发送裸ID。

Problem was in this code. Actually i was sending the bare id every time when i was inviting any user.

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")

        }

    }

但邀请任何用户使用完整身份证。

对于那些不知道的人

BareID = username @ domain
FullID = username @ domain / resource

BareID = username@domain FullID = username@domain/resource

至解决这个问题

我在整个应用程序的JID中硬编码资源= APPNAME。

I hardcode the resource = APPNAME everywhere in JIDs in whole app.

这篇关于在XMPPFramework和Swift 2中没有调用didReceiveInvitation()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆