XMPPFramework
XMPPFramework copied to clipboard
Join to room, freeze app
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?
Anyone can help me?
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?
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.
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).
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.
Yeah, I meant like that :smile:
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;
}
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?
Hi,
I've 5 rooms. How can use instrument to find the statement where the app frezees?
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.
Did you manage to solve this?
Did you get any solution for this ? Please share if you have some valuable solution. Thanks
Hi All, I am facing same hanging issues, I have 100+ room to join, It is taking 25+ seconds to join all room. Can any one help in this?
Thanks.
Hi ObjColumnist/CeccoCQ, I am facing same hanging issues, I have 100+ room to join, It is taking 25+ seconds to join all room. Can any one help in this?
I did same, and it work fast but, is there possibility if too many threads are joining in background and same time other one doing database operation then is there any possibility of crashing because i am facing issue in iOS10?
Thanks.
Hi All I am facing same freeze issues,Can anyone solve this problem?
Thanks.
can anyone tell me how to join a room I am not able to join a room I write this method when user get Authenticated, but interestingly delegates method of room not called
func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
print("auth done")
xmppMUC.activate(stream)
xmppMUC?.addDelegate(self, delegateQueue: DispatchQueue.main)
let roomJID = XMPPJID(string: "[email protected]")
let roomStorage = XMPPRoomCoreDataStorage.sharedInstance()
xmppRoom = XMPPRoom(roomStorage: roomStorage, jid: roomJID, dispatchQueue: DispatchQueue.main)!
xmppRoom.activate(stream)
xmppRoom.addDelegate(self, delegateQueue: DispatchQueue.main)
xmppRoom.join(usingNickname: stream?.myJID.user, history: nil)
print("xmppRoom.isJoined",xmppRoom.isJoined)
}
Please help me and tell me where to add this snippets is it better to add after user get authenticated.