【问题标题】:iOS - XMPPFramework - creating a group chatroom - IssueiOS - XMPPFramework - 创建群聊室 - 问题
【发布时间】:2014-06-16 04:08:54
【问题描述】:

我正在 iOS 中开发一个聊天应用程序。在 XMPP 服务器(在本例中为 Ejabberd,我启用了 MUC)。我已经注册了一个用户,现在尝试使用注册用户创建一个聊天室。同样在 MUC 中,正确定义了 Host 设置

{host, "conference.@HOST@"}

但我无法创建聊天室

我使用的代码如下

XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init]; 
NSString *jid =[[NSUserDefaults standardUserDefaults] valueForKey:@"UserName"]; 
jid=[jid stringByReplacingOccurrencesOfString:@"@localhost" withString:@""]; 
jid=[jid stringByAppendingString:@"@conference.localhost"]; 
NSLog(@"jid is here :%@",jid); 
// timok@conference.localhost 

XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID     jidWithString:jid] dispatchQueue:dispatch_get_main_queue()]; 
[xmppRoom activate:[appdel xmppStream]]; 

[xmppRoom fetchConfigurationForm]; 

[xmppRoom configureRoomUsingOptions:nil]; 
[xmppRoom addDelegate:appdel delegateQueue:dispatch_get_main_queue()]; 
[xmppRoom inviteUser:[XMPPJID jidWithString:@"motik@localhost"] withMessage:@"Hi join room"];

在上面的代码中,timok 和 motik 是注册用户。当我尝试创建房间时,出现以下错误

2014-04-29 18:25:27:996 konnectlinks[16112:5e03] SEND: <message to="timok@conference.localhost"><x xmlns="http://jabber.org/protocol/muc#user"><invite to="motik@localhost"><reason>Hi join room</reason></invite></x></message> 
2014-04-29 18:25:28:280 konnectlinks[16112:5a43] RECV: <iq xmlns="jabber:client" from="localhost" id="99D56CEF-3DEA-4D3D-B186-D3B1C28FEE8F" type="error"><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq> 
2014-04-29 18:25:28:280 konnectlinks[16112:a0b] paduaAppDelegate: xmppStream:didReceiveIQ: 
2014-04-29 18:25:28:564 konnectlinks[16112:5a43] RECV: <iq xmlns="jabber:client" from="localhost" id="D9F3BE9A-F4EB-4361-8F1A-C51FD5880AD8" type="error"><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq> 
2014-04-29 18:25:28:564 konnectlinks[16112:a0b] paduaAppDelegate: xmppStream:didReceiveIQ: 
2014-04-29 18:25:28.564 konnectlinks[16112:a0b] didNotConfigure

任何有关如何解决此问题的想法都会非常有帮助。

【问题讨论】:

标签: ios xmpp ejabberd xmppframework


【解决方案1】:

试试这个

 - (void)createOrJoinRoomWithRoomName:(NSString *)roomName nickName:(NSString *)nickName 
        {
            if(roomName && nickName)
            {
                _xmppRoomStorage = [XMPPRoomHybridStorage sharedInstance];
                XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@.%@",roomName,@"conference",self.hostName]];
                _xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:_xmppRoomStorage jid:roomJid];
                [_xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
                [_xmppRoom activate:_xmppStream];
                NSXMLElement *history = [NSXMLElement elementWithName:@"history"];
                [history addAttributeWithName:@"maxstanzas" stringValue:MAX_ROOM_HISTORY];
                [_xmppRoom joinRoomUsingNickname:nickName history:history];
            }
            else
            {
                NSLog(@"room creation arguments missing");
            }
        }

【讨论】:

    【解决方案2】:
    -(void) createOrJoinEventGroupChat:(NSString *) groupJID{
    
         XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",groupJID,SERVER_URL]];     
    
         XMPPRoom *muc = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
    
         [muc   activate:xmppStream];
    
         [muc   addDelegate:self delegateQueue:dispatch_get_main_queue()];
    
         [muc   joinRoomUsingNickname:@"User Name" history:nil];
    
    }
    

    【讨论】:

      【解决方案3】:

      创建 MUC 房间

      - (void)createChatRoom:(NSString *) newRoomName
      {
          NSString * xmppRoomJID = [NSString stringWithFormat:@"%@@%@", newRoomName, CONFERENCE_ROOM_SERVER_NAME];
          XMPPJID *roomJID = [XMPPJID jidWithString:xmppRoomJID];
      
          XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
      
          xmppRoom = [[XMPPRoom alloc]
                      initWithRoomStorage:roomMemoryStorage
                      jid:roomJID
                      dispatchQueue:dispatch_get_main_queue()];
      
          [xmppRoom activate:[self xmppStream]];
          [xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
          [xmppRoom joinRoomUsingNickname:[Your Nickname or Number Here] history:nil];
          [xmppRoom fetchConfigurationForm];
      
      }
      

      【讨论】:

        猜你喜欢
        • 2012-02-20
        • 1970-01-01
        • 2013-03-05
        • 2013-09-24
        • 2013-10-16
        • 2014-01-19
        • 2011-09-19
        • 1970-01-01
        • 2011-11-06
        相关资源
        最近更新 更多