Game Kit stores a strong reference to the completion handler that I send to authenticateWithCompletionHandler:, which means that each time the user exits and enters the app, it gets called again. This makes sense, but it causes a problem with a use case I have:
1) I prompt the user to log into Game Center when the app launches.
2) They tap Cancel because they want to play single player for a while. Therefore they are not logged in.
3) At some point, they decide they want to play online, so they tap my "Play Online" button.
4) This ought to show a screen where they can set up online game options, etc, but I notice they have no authenticated player, so…
5) I prompt the user again to log in to Game Center.
6) The user logs in this time, and in the completion handler I show my online game options screen.
Step 6 is the where the problem lies: every time the user leaves and re-enters the app, it will show my game options screen, because my completion handler is repeated. If I take out the code in the completion handler to show the online game options, the user has to tap the button twice - once to login, and once again to show the online options.
What is the smart solution to this?
For reference, a simplified version of my code looks like this:
- (IBAction)playOnlineTapped:(id)sender
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.authenticated) {
[self showOnlineGameOptions];
}
}];
}
So many of the examples I have read assume that the user logs in first time, but I don't think that's always going to be the case.
Thanks in advance for your help!