Skip to content

Loading…

Join to room, freeze app #206

Open
CeccoCQ opened this Issue · 12 comments

3 participants

@CeccoCQ

I'm trying to develop a method called
-(void) autoJoin:(NSArray*) rooms

where into rooms array there are a list of active rooms related to the user.

If I execute a lot of join into users rooms, my application freezes for a while, then when the join is complete, the app works correctly.
My purpose is to execute this autojoin method when user was authenticated at my xmpp server (currently is openfire).

Is there a way to execute this method within the global_queue and not in the main_queue?

@CeccoCQ

Anyone can help me?

@ObjColumnist
Collaborator

I haven't used the MUC code so I am probably not the best person to comment, but what does the code inside autoJoin: look like?

@CeccoCQ

It's a simply "for" :

for(NSString *roomRealJid in myRoomsJidArray) 
{ 
    XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomRealJid];
    [newXmppRoom fetchConfigurationForm];
    [newXmppRoom activate: xmppStream];
    [newXmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [newXmppRoom joinRoomUsingNickname:xmppStream.myJID.user history:nil];
}

This operation freezes my app, so I can't join automatically to all my room at login.

@ObjColumnist
Collaborator

All of the code looks like it should run on a background queue asynchronously, have you tried passing in the default high priority queue into the initWithRoomStorage method? You should call activate first (before calling fetchConfigurationForm).

You probably need to work out with one of those method calls is taken up the most time (e.g. put log statements, use instruments etc).

@CeccoCQ

Do you mean something like this snippet?

XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomRealJid dispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
[newXmppRoom activate: xmppStream];   
[newXmppRoom fetchConfigurationForm];
[newXmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[newXmppRoom joinRoomUsingNickname:xmppStream.myJID.user history:nil];

I didn't understan because I've to insert activate method before fetchConfigurationForm.

@ObjColumnist
Collaborator

Yeah, I meant like that :smile:

@CeccoCQ

I've tried, nothing.
My ViewController still freezes!

This is my code:

- (void) autoJoin {
for(NSString *roomRealJid in myRoomsJidArray) 
        [self joinRoom:roomRealJid];
    }
}

- (XMPPRoom*) joinRoom:(NSString*) roomJid {

    if(!isXmppAuthenticated) {
        return nil;
    }

    XMPPJID *roomRealJid = [XMPPJID jidWithString:roomJid];
    XMPPRoom *newXmppRoom = [[XMPPRoom alloc] initWithRoomStorage:xmppRoomStorage jid:roomRealJid dispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
    [newXmppRoom activate: xmppStream];
    [newXmppRoom fetchConfigurationForm];
    [newXmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [newXmppRoom joinRoomUsingNickname:xmppStream.myJID.user history:nil];
    return newXmppRoom;
}
@ObjColumnist
Collaborator

Your code looks fine to me, I think you will need to profile the code and work out what method is actually locking the app up.

How many rooms are you trying to add?

@CeccoCQ

Hi,

I've 5 rooms. How can use instrument to find the statement where the app frezees?

@ObjColumnist
Collaborator

You can use the time profiler to measure how long each method takes.

I expect logging the date between each method call might be sufficient though.

@ObjColumnist
Collaborator

Did you manage to solve this?

@HBIOSDev

Did you get any solution for this ? Please share if you have some valuable solution.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.