GameCenter login alert

Alex picture Alex · Nov 30, 2010 · Viewed 11.2k times · Source

In a game I am developing using GameCenter, I want to handle the following scenario:

  1. the user starts up the game. He is shown the system alert that prompts him to log on GameCenter. He ignores it for now.
  2. after a while, the user wants to log in to GameCenter and clicks on(for instance) the Leaderboards menu item. He choses cancel instead of Log in, for now.
  3. the process repeats several times. Eventually the user DOES want to log in to GameCenter. He clicks the Leaderboard menu item one more time.

In my tests, I have found that the alert popup raised by the call to "authenticateWithCompletionHandler" (as invoked by Apple's sample GameCenterManager) which suggests to log in to GameCenter only appears a limited number of times(4 or 5). The last time it appears, it says "Game Center Disabled, sign in with the Game Center application to enable"Afterwards". Afterwards, calling authenticateWithCompletionHandler no longer does anything visible -no prompt at all.

Playing FruitNinja I tried to replicate this. However, in their case, the popup saying "Game Center Disabled" does appear every time I click on a GameCenter item(Achievements, for instance).

What I'd like to do is to duplicate the functionality: that is, if you are not logged in to GameCenter, to have the standard game center alert appear all the times you click on the Leaderboard menu item.

Is there a way to learn whether the standard 'log in to game center' alert has appeared, or to force it to appear at all times(and not just the first couple of tries)?

Answer

thumbsup picture thumbsup · Jan 16, 2012

Here's an is an idea to workaround this issue:

No matter if a "GC authenticateWithCompletionHandler"-Request is cancelled

  • by the user tapping "Cancel" in the dialog

or due to the fact that

  • GC is disabled on the device (which happens after the user has cancelled the alert-dialog exactly 3 times (in iOS 5 at least))

you will always receive an NSError with code 2 saying "The requested operation has been cancelled.".

The only differentiator that i could find is the time passed between the authenticateWithCompletionHandler-Request and the the execution of the completion-Handler.

So when sending the request i am saving the time:

requestTime = [NSDate date]; 

and in my completion handler i measure the time lapsed:

NSDate* now = [NSDate date];
CFTimeInterval elapsedTimeSinceAuthenticationRequest = [now timeIntervalSinceDate:requestTime];
NSLog(@"time Elapsed: %f", elapsedTimeSinceAuthenticationRequest);

If the user cancelled the request, the time passed will be significantly longer compared to the time passed if GC cancelled the operation. In my tests, it took a user at least one second to cancel the dialog, whereas a GC-cancelled request took less than 0.1 seconds (on my iPhone 4)

Of course, these values may vary depending on the device the code runs on and on what else the processor is busy with at the moment. One pitfall i already examined is the application launch: If you are sending the authenticationRequest during applicationDidFinishLaunching as suggested by Apple, it took much longer for GC to cancel the request in my case, because the device is busy loading views and whatever is necessary to launch the app.

So let me know if you tried this solution and if it worked for you, as will i once i have done further testing...