我正在使用此代码,但我的应用程序挂了一段时间,我也想每隔5分钟运行一次这个功能。我可以添加任何代码,用于停止挂起UI并在5分钟后运行。
- (无效)ConnectRoom { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0),^ {
//Do EXTREME PROCESSING!!!
// for (int i = 0; i< 100; i++) {
// [NSThread sleepForTimeInterval:.05];
// NSLog(@"%i", i);
// Create strong reference to the weakSelf inside the block so that it´s not released while the block is running
for (int i=0; i<arrRoomData.count; i++)
{
[NSThread sleepForTimeInterval:0.1];
if ([arrRoomData objectAtIndex:i])
{
if ( [arrJoinedRoom containsObject: [arrRoomData objectAtIndex:i]] )
{
} else
{
// do not found
XMPPRoomMemoryStorage *roomStorage;
roomStorage=[[XMPPRoomMemoryStorage alloc] init];
XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@/%@",[arrRoomData objectAtIndex:i],ipAddress,[[NSUserDefaults standardUserDefaults] valueForKey:@"UserLoginID"] ]];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage jid:roomJID dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:self.xmppStream];
[self.roomDict setObject:xmppRoom forKey:[arrRoomData objectAtIndex:i]];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:[[NSUserDefaults standardUserDefaults]valueForKey:@"UserLoginID" ] history:nil password:nil];
//[self performSelector:@selector(ConnectRoom:)
// withObject:[arrRoomData objectAtIndex:i]
// afterDelay:8.5];
}
}
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"background puneet test ");
});
//}
});
}
由于