XMPPFrameWork IOS 开发 创建聊天室不能持久保存的解决办法

来源:互联网 发布:webshell采集器 编辑:程序博客网 时间:2024/05/22 04:28

创建 聊天室代码如下

    

    xmppRoomCoreDataStorage = [XMPPRoomCoreDataStoragesharedInstance];    XMPPJID *jid = [XMPPJIDjidWithString:@"XXX@conference.XXX"];    xmppRoom = [[XMPPRoomalloc]initWithRoomStorage:xmppRoomCoreDataStoragejid:jid];    [xmppRoom activate:xmppStream];    [xmppRoomaddDelegate:selfdelegateQueue:dispatch_get_main_queue()];    [xmppRoomjoinRoomUsingNickname:@"XXX"history:nil];    [xmppRoomfetchConfigurationForm];


会执行 - (void)xmppRoomDidCreate:(XMPPRoom *)sender 代理 说明聊天室创建成功。


当离线后,发现不能获取此聊天室,经查找配置,发现应设置以下代码才会永久保存聊天室:

- (void)xmppRoomDidCreate:(XMPPRoom *)sender {    NSXMLElement *field = [NSXMLElementelementWithName:@"field"];    [field addAttributeWithName:@"type"stringValue:@"boolean"];    [field addAttributeWithName:@"var"stringValue:@"muc#roomconfig_persistentroom"];    [field addChild:[NSXMLElementelementWithName:@"value"objectValue:@"1"]];  // 将持久属性置为YES。    NSXMLElement *x = [NSXMLElementelementWithName:@"x"xmlns:@"jabber:x:data"];    [x addAttributeWithName:@"type"stringValue:@"form"];    [x addChild:field];    [senderconfigureRoomUsingOptions:x];}


贴上配置xml,备份查看

<?xml version="1.0" encoding="utf-8"?><x xmlns="jabber:x:data" type="form">  <title>Configuration of room XXX@conference.XXX</title>  <field type="hidden" var="FORM_TYPE">    <value>http://jabber.org/protocol/muc#roomconfig</value>  </field>  <field type="text-single" label="Room title" var="muc#roomconfig_roomname">    <value/>  </field>  <field type="text-single" label="Room description" var="muc#roomconfig_roomdesc">    <value/>  </field>  <field type="boolean" label="Make room persistent" var="muc#roomconfig_persistentroom">    <value>0</value>  </field>  <field type="boolean" label="Make room public searchable" var="muc#roomconfig_publicroom">    <value>1</value>  </field>  <field type="boolean" label="Make participants list public" var="public_list">    <value>1</value>  </field>  <field type="boolean" label="Make room password protected" var="muc#roomconfig_passwordprotectedroom">    <value>0</value>  </field>  <field type="text-private" label="Password" var="muc#roomconfig_roomsecret">    <value/>  </field>  <field type="list-single" label="Maximum Number of Occupants" var="muc#roomconfig_maxusers">    <value>200</value>    <option label="5">      <value>5</value>    </option>    <option label="10">      <value>10</value>    </option>    <option label="20">      <value>20</value>    </option>    <option label="30">      <value>30</value>    </option>    <option label="50">      <value>50</value>    </option>    <option label="100">      <value>100</value>    </option>    <option label="200">      <value>200</value>    </option>  </field>  <field type="list-single" label="Present real Jabber IDs to" var="muc#roomconfig_whois">    <value>moderators</value>    <option label="moderators only">      <value>moderators</value>    </option>    <option label="anyone">      <value>anyone</value>    </option>  </field>  <field type="boolean" label="Make room members-only" var="muc#roomconfig_membersonly">    <value>0</value>  </field>  <field type="boolean" label="Make room moderated" var="muc#roomconfig_moderatedroom">    <value>1</value>  </field>  <field type="boolean" label="Default users as participants" var="members_by_default">    <value>1</value>  </field>  <field type="boolean" label="Allow users to change the subject" var="muc#roomconfig_changesubject">    <value>1</value>  </field>  <field type="boolean" label="Allow users to send private messages" var="allow_private_messages">    <value>1</value>  </field>  <field type="list-single" label="Allow visitors to send private messages to" var="allow_private_messages_from_visitors">    <value>anyone</value>    <option label="nobody">      <value>nobody</value>    </option>    <option label="moderators only">      <value>moderators</value>    </option>    <option label="anyone">      <value>anyone</value>    </option>  </field>  <field type="boolean" label="Allow users to query other users" var="allow_query_users">    <value>1</value>  </field>  <field type="boolean" label="Allow users to send invites" var="muc#roomconfig_allowinvites">    <value>0</value>  </field>  <field type="boolean" label="Allow visitors to send status text in presence updates" var="muc#roomconfig_allowvisitorstatus">    <value>1</value>  </field>  <field type="boolean" label="Allow visitors to change nickname" var="muc#roomconfig_allowvisitornickchange">    <value>1</value>  </field>  <field type="boolean" label="Allow visitors to send voice requests" var="muc#roomconfig_allowvoicerequests">    <value>1</value>  </field>  <field type="text-single" label="Minimum interval between voice requests (in seconds)" var="muc#roomconfig_voicerequestmininterval">    <value>1800</value>  </field>  <field type="jid-multi" label="Exclude Jabber IDs from CAPTCHA challenge" var="muc#roomconfig_captcha_whitelist"/></x>


0 0
原创粉丝点击