【发布时间】:2018-01-31 13:33:44
【问题描述】:
我正在使用 Robbiehanson 的 XMPPFramework 开发一个聊天应用程序,当我的应用程序收到很多节时,应用程序的 UI 冻结,这就是我制作我的流的方式。
当框架尝试针对收到的消息发送回执或流管理器尝试针对收到的节发送确认时,应用程序的 UI 大多会冻结。
这就是我设置直播的方式。
//流设置
if (!self.xmppStream || ![self.xmppStream isConnected]) {
self.xmppStream = [[XMPPStream alloc] init];
[self.xmppStream setHostName:kGetChatServerURLString];
// [self.xmppStream setHostPort:kBPChatServerPort];
[self.xmppStream setHostPort:kBPChatServerPort];
[self.xmppStream setStartTLSPolicy:XMPPStreamStartTLSPolicyAllowed];
self.xmppReconnect = [ [XMPPReconnect alloc] init];
[self.xmppReconnect setAutoReconnect:YES];
self.xmppRosterMemStorage = [[XMPPRosterMemoryStorage alloc] init];
self.xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:self.xmppRosterMemStorage dispatchQueue:dispatch_get_main_queue()];
self.xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = true;
self.xmppRoster.autoFetchRoster = true;
[self.xmppRoster activate:self.xmppStream];
self.xmppMUC = [[XMPPMUC alloc] initWithDispatchQueue:_backgroundQueue];
[self.xmppMUC activate:self.xmppStream];
// To enable socket in the background.
[self.xmppStream setEnableBackgroundingOnSocket:YES];
// Moved the function to here from DidConnect to fix multiple delivery reports sending issue after reconnect.
[self setupAutoSendDeliveryReceipts];
XMPPMessageCarbons *xmppMessageCarbon = [[XMPPMessageCarbons alloc] initWithDispatchQueue:_backgroundQueue];
[xmppMessageCarbon activate:self.xmppStream];
[xmppMessageCarbon setAutoEnableMessageCarbons:YES];
//XEP-0191: Blocking Command
self.xmppBlocking = [[XMPPBlocking alloc] initWithDispatchQueue:_backgroundQueue];
[self.xmppBlocking activate:self.xmppStream];
[self.xmppStream addDelegate:self delegateQueue:_backgroundQueue];
[self.xmppReconnect addDelegate:self delegateQueue:_backgroundQueue];
[self.xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
[self.xmppMUC addDelegate:self delegateQueue:_backgroundQueue];
[self.xmppBlocking addDelegate:self delegateQueue:_backgroundQueue];
[[BPCXMPPvCardStorageManager sharedInstance] activateWithStream:self.xmppStream];
[[BPCChatRoomsManager sharedManager] activateWithStream:self.xmppStream];
}
//设置流管理器
- (void)setupStreamManagement {
if (kBPCTempEnableStreamManagement) {
//Intialize with XMPPStreamManagementMemoryStorage
XMPPStreamManagementMemoryStorage *xmppSMMS = [[XMPPStreamManagementMemoryStorage alloc] init];
self.xmppStreamManagement = [[XMPPStreamManagement alloc] initWithStorage:xmppSMMS dispatchQueue:_backgroundQueue];
//Activate with stream
[self.xmppStreamManagement activate:self.xmppStream];
self.xmppStreamManagement.autoResume = YES;
[self.xmppStreamManagement enableStreamManagementWithResumption:YES maxTimeout:0];
[self.xmppStreamManagement requestAck];
[self.xmppStreamManagement sendAck];
[self.xmppStreamManagement automaticallySendAcksAfterStanzaCount:1 orTimeout:0];
}
}
//启用自动消息传递
XMPPMessageDeliveryReceipts *xmppMessageDeliveryReceipts = [[XMPPMessageDeliveryReceipts alloc] initWithDispatchQueue:dispatch_queue_create("messageDeliverReceiptsQueue", DISPATCH_QUEUE_CONCURRENT)];
xmppMessageDeliveryReceipts.autoSendMessageDeliveryReceipts = YES;
xmppMessageDeliveryReceipts.autoSendMessageDeliveryRequests = YES;
[xmppMessageDeliveryReceipts activate:self.xmppStream];
我使用的后台队列是:
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
我该如何解决这个问题?
【问题讨论】:
-
如果使用
automaticallySendAcksAfterStanzaCount,则不需要sendAck。
标签: ios objective-c sockets xmppframework