0

I am trying to sign in game center usign following code :-

 [[GKLocalPlayer localPlayer]   authenticateWithCompletionHandler:^(NSError *error)
 {
     if (error == nil)
     {
         NSLog(@"Authentication Successful");
     }

     else
     {
         NSLog(@"Authentication Failed");
     }
 }];

:- At first it opens the gamecenter but when user press cancel button and comes again the game center screen is not opening and showing the following error "The requested operation has been canceled or disabled by the user".

Please suggest when this happening and how correct it.

YvesLeBorg
  • 9,070
  • 8
  • 35
  • 48
user4388479
  • 19
  • 1
  • 6
  • Read the documentation. This method was deprecated in iOS6. No matter what it returns... you shouldn't be using it. – Fogmeister Jan 14 '16 at 13:58

1 Answers1

2

Regardless of whether you're using the deprecated method in the original post or the current preferred mechanism (as of this writing),

[[GKLocalPlayer localPlayer] setAuthenticateHandler:^(UIViewController *loginViewController, NSError *error)
{

}];

you only get one shot at authenticating. If you try setting the authentication handler again later, the login screen will not appear again. These links talk more about that:

Killing the app (not just switch away, but actually close the app) and restarting it will cause the login to appear again when you attempt to authenticate. Alternatively, switching to the game center app should allow the user to log in.

So, in my app, I check the error code. If the user cancels, the error.code in the handler will be set to 2. When I see this value, I disable all game center functionality and I put up a notice to the user stating what they need to do to complete logging in.

Community
  • 1
  • 1
Thunk
  • 4,099
  • 7
  • 28
  • 47