10

I have a problem with logging a user to the Game Center. I first present the login dialog right after the application finishes loading. If the user cancels the dialog, I want to give him the option to change his mind by providing a login button in my main menu. However, on iPads with iOS7, the button doesn't do anything - the Game Center dialog doesn't get shown (it works correctly on iOS6). Instead, I immediately get the error "The requested operation has been cancelled or disabled by the user." Same code is called on application launch and on the button tap. It uses the authenticateWithCompletionHandler method and basically looks like:

GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error)
{
    OnLogin(error);
}];

(I know the method is deprecated, but my experience with the new one has been even worse).

The interesting thing is that the GC dialog DOES appear if I move the application to the background and then bring it back to the foreground.

The issue I describe happens even after the first cancel, so I don't think it has anything to do with Game Center banning applications after 3 cancels.

Does anyone know how to fix this?

user2986426
  • 103
  • 1
  • 5
  • Does [this answer](http://stackoverflow.com/a/20895803/2880276) help? – Joseph Chen Jan 10 '14 at 11:39
  • 1
    @JosephChen "If the user cancels the presented login screen, calling these methods again does nothing, or rather, the completion handler is called with an error. The user will then need to login to GameCenter through the GameCenter app or through the Settings app." Do you know if that's the behavior intended by Apple? Can you provide any links on that? If that is the case, please post it as the answer; if you can link the behavior to, for example, Apple docs, I will gladly accept it. – user2986426 Jan 15 '14 at 07:08
  • Hi, I did manage to find something on this, even though I didn't see it when making that earlier post. Details below... – Joseph Chen Jan 15 '14 at 08:07

1 Answers1

11

In regards to your comment, I found the Apple documentation that mentions Game Kit's policy of not asking a user to login again after they have cancelled login once.

It's in the Game Center Programming Guide under Common Tasks When Working with Players > Authenticating a Local Player on the Device. (bold type is mine)

Important: Game Kit handles opting out of Game Center across all games that support Game Center. If a player has already declined to create an account, when your game authenticates the player, it is told there is no authenticated player. The player never sees an authentication dialog. Because Game Kit handles this process across all games, your game should not include its own mechanism to disable Game Center authentication or ask a player’s permission to authenticate. Instead, your game should simply authenticate the player every time it launches and respond appropriately when authentication completes.

You can confirm this by including an NSLog in the authentication handler to show each time the handler is called and whether it succeeded or failed. Hope this helps...

Mattias
  • 3,907
  • 4
  • 28
  • 50
Joseph Chen
  • 1,520
  • 13
  • 21
  • As a matter of fact, I've read that part some time ago, but somehow it didn't click with me that it basically describes the problem I'm facing. I still think they could have been a bit more explicit on that (I personally find "declined to create an account" a bit cryptic, to be honest). Anyway, thanks a lot for your help! – user2986426 Jan 15 '14 at 08:43
  • 2
    Though it's still not clear why the dialog DOES get shown after bringing the app to background and to foreground again. – user2986426 Jan 15 '14 at 08:45