Handling an iOS app that resigns active

edited June 2013 in Native
So, we are creating a game with a combination of Cocos2d-x, LoadBalancing Client and Photon Cloud. Now, if a user "quits" the app during a multiplayer session he has about 5 seconds to return or else he will get disconnected by a connection error 1041. Since our game is turn-based we want to be a bit more lenient with that time, so our users don't get punished, e.g. for pressing an ad.

Here is what I am trying to do:

On applicationWillResignActive:

Room name gets saved. The scheduler that calls service() gets stopped. LoadBalancing Client gets disconnected. service() gets called one last time, so the disconnect actually happens

On applicationDidBecomeActive:

LoadBalancing Client connects again. Scheduler gets restarted. Upon connectReturn getting called, client tries to join room with saved name

What actually happens

Disconnect seems to work, as leaveRoomEventAction get called on the other client. But when the first client tries to reconnect, the service calls only yield a disconnectReturn and connectReturn never gets called. To make things even more confusing, I am pretty sure it worked once

So, is this approach even feasible and if yes, what do I need to fix? If no, is there any other way to achieve this goal?

My code for this is kind of all over the place, so I am not exactly sure, if posting it would help. Just tell me, if you need to know more


  • Aaaand of course I figured it out 2 minutes later:

    I just need to call service() once before initializing reconnection, to actually get the disconnect. Works like a charm now
Sign In or Register to comment.