chatContactListDidChange方法每当chatDidLogin方法发送在线计时器时触发

时间:2014-07-15 00:12:39

标签: quickblox


更新我最后只是添加了一个刷新按钮,供用户手动刷新联系人列表。我想如果你们想让更多的小型开发人员使用Quickblox用于社交应用程序,比如消息和东西,你应该为联系人列表添加更多文档和示例。它是任何社交应用程序的核心功能,但您只需要在其中添加一个段落,以及一个完整的静态数据代码片段,这些代码片段无法应用于真实世界的应用程序。

例如,您对联系人列表的一个答案是说- (void)chatDidReceiveContactAddRequestFromUser:(NSUInteger)userID{ [[QBChat instance] confirmAddContactRequest:userID]; }接受朋友请求。该方法使得用户无法接受或拒绝朋友请求,但自动接受收到的每个朋友请求。它应该允许用户选择拒绝或接受请求,而无需建立额外的列表来跟踪您已接受或拒绝的请求。


在我的chatContactListDidChange方法中

- (void)chatContactListDidChange:(QBContactList *)contactList{
    [[NSNotificationCenter defaultCenter] postNotificationName:ContactListChanged object:nil];
    NSLog(@"contact list changed");
    NSLog(@"current contact list %@", [QBChat instance].contactList);
}

和chatDidLogin

- (void)chatDidLogin{
    // Start sending presences
    [self.presenceTimer invalidate];
    self.presenceTimer = [NSTimer scheduledTimerWithTimeInterval:5
                                     target:[QBChat instance] selector:@selector(sendPresence)
                                   userInfo:nil repeats:YES];

    if(self.loginCompletionBlock != nil){
        self.loginCompletionBlock();
        self.loginCompletionBlock = nil;
    }
}

即使没有用户更改其状态,也会每5秒触发一次chatContactListDidChange方法。这是日志

2014-07-14 18:52:30.076 sample-chat[45514:3d07] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-07-14 18:52:30.124 sample-chat[45514:90b] contact list changed
2014-07-14 18:52:30.125 sample-chat[45514:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)
2014-07-14 18:52:35.075 sample-chat[45514:3d07] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-07-14 18:52:35.128 sample-chat[45514:90b] contact list changed
2014-07-14 18:52:35.128 sample-chat[45514:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)
2014-07-14 18:52:40.075 sample-chat[45514:401f] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-07-14 18:52:40.129 sample-chat[45514:90b] contact list changed
2014-07-14 18:52:40.129 sample-chat[45514:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)
2014-07-14 18:52:45.075 sample-chat[45514:401f] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-07-14 18:52:45.148 sample-chat[45514:90b] contact list changed
2014-07-14 18:52:45.148 sample-chat[45514:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)

我尝试关闭在线状态计时器,但随后出现断开连接错误QBChat/didDisconnect, error: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0xd4b0e30 {NSLocalizedDescription=Socket closed by remote peer}

另外,当我第一次以用户身份登录时,chatContactListDidChange方法会立即触发4次,这是

的日志
2014-07-14 19:15:23.810 sample-chat[45629:3e03] -[QBChat xmppStream:didSendIQ:] -> IQ: <iq type="get" id="561006823"><query xmlns="jabber:iq:roster"/></iq>
2014-07-14 19:15:23.810 sample-chat[45629:3e03] -[QBChat xmppStream:didSendPresence:] -> Presence: <presence/>
2014-07-14 19:15:23.810 sample-chat[45629:90b] waiting for approval = (
)
2014-07-14 19:15:23.811 sample-chat[45629:90b] contact list changed
2014-07-14 19:15:23.811 sample-chat[45629:3e03] -[QBChat xmppStream:didReceiveIQ:] -> <iq xmlns="jabber:client" to="1278228-11606@chat.quickblox.com/tigase-169625" type="result" id="561006823"><query xmlns="jabber:iq:roster"><item name="1290038-11606" subscription="none" jid="1290038-11606@chat.quickblox.com"/><item name="1286872-11606" ask="subscribe" subscription="none" jid="1286872-11606@chat.quickblox.com"/><item name="1287012-11606" ask="subscribe" subscription="none" jid="1287012-11606@chat.quickblox.com"/><item name="1287015-11606" ask="subscribe" subscription="none" jid="1287015-11606@chat.quickblox.com"/><item name="1289912-11606" ask="subscribe" subscription="none" jid="1289912-11606@chat.quickblox.com"/><item name="1289984-11606" ask="subscribe" subscription="none" jid="1289984-11606@chat.quickblox.com"/></query></iq>
2014-07-14 19:15:23.811 sample-chat[45629:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)
2014-07-14 19:15:23.947 sample-chat[45629:90b] waiting for approval = (
)
2014-07-14 19:15:23.946 sample-chat[45629:3e03] Request finished, response:
headers:{
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "max-age=0, private, must-revalidate";
    Connection = "keep-alive";
    "Content-Type" = "application/xml; charset=utf-8";
    Date = "Tue, 15 Jul 2014 00:15:23 GMT";
    Etag = "\"6b46ffce805a218f9a8eb3082dca64b7\"";
    "QB-Token-ExpirationDate" = "2014-07-15 02:15:23 UTC";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "nginx/1.0.15";
    Status = "201 Created";
    "Transfer-Encoding" = Identity;
    "X-Rack-Cache" = "invalidate, pass";
    "X-Request-Id" = 7122bfedd350cab031cdaf1375b28e7f;
    "X-Runtime" = "0.018427";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<session>
  <_id>53c4729b535c123d96004e43</_id>
  <application-id type="integer">11606</application-id>
  <created-at type="datetime">2014-07-15T00:15:23Z</created-at>
  <device-id type="integer">0</device-id>
  <nonce type="integer">453</nonce>
  <token>60d472f2c86e587151bd5fa1c61db1924675fcf6</token>
  <ts type="integer">1405383323</ts>
  <updated-at type="datetime">2014-07-15T00:15:23Z</updated-at>
  <user-id type="integer">1278228</user-id>
  <id type="integer">24054</id>
</session>
error:
2014-07-14 19:15:23.947 sample-chat[45629:90b] contact list changed
2014-07-14 19:15:23.947 sample-chat[45629:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)
2014-07-14 19:15:23.948 sample-chat[45629:90b] waiting for approval = (
)
2014-07-14 19:15:23.948 sample-chat[45629:90b] contact list changed
2014-07-14 19:15:23.948 sample-chat[45629:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)
2014-07-14 19:15:23.949 sample-chat[45629:90b] waiting for approval = (
)
2014-07-14 19:15:23.949 sample-chat[45629:90b] contact list changed
2014-07-14 19:15:23.949 sample-chat[45629:90b] current contact list 
[ContactList] 
     contacts: (
) 
     pendingApproval: (
    "  userId: 1287015, online: 0, subscriptionState: none",
    "  userId: 1289912, online: 0, subscriptionState: none",
    "  userId: 1289984, online: 0, subscriptionState: none",
    "  userId: 1287012, online: 0, subscriptionState: none",
    "  userId: 1286872, online: 0, subscriptionState: none"
)

0 个答案:

没有答案