2

I am using this code but my app hangs for some time and i also want to run this function in every 5 mins.Any code which i can add for stopping the hang the UI and run after 5 min.

-(void)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 ");
    });

    //}

});

}

Thanks

Balaji Cgt
  • 21
  • 3

0 Answers0