Authenticating GKLocalPlayer with Game Center
I am trying to authenticate a GKLocalPlayer with Game Center. However, the code supplied by Apple
- (void) authenticateLocalPlayer
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil)
{
// Insert code here to handle a successful authentication.
NSLog(@"Logged in.");
}
else
{
// Your application can process the error parameter to report the error to the player.
NSLog(@"%@", [error description]);
}
}];
}
does not see开发者_高级运维m to do the trick for me. I always get an alert "Could not connect to Game Center server." with the option to "Retry" or "Cancel". Neither of the NSLog statements is executed, so I guess that the completionHandler is not even fired.
If I press retry, I get the following error:
Error Domain=GKErrorDomain Code=7 "The requested operation could not be completed because local player is already authenticating." UserInfo=0x8915f80 {NSLocalizedDescription=The requested operation could not be completed because local player is already authenticating.}
Anyone have any idea what is going wrong?
One possible problem I found with connecting to Game Center is that your date may be wrong on the device. Check if your date is the actual current date. Somehow Game Center does not allow connections from devices with incorrect dates.
You may try to reset the simulator to default entirely. It worked for me, once it is reset, my iDevice works again.
Depend on the ios version you couldn't log in, then set the simulator to foreground and go to the upper left. iOS Simulator -> Reset Content and Settings -> Click on Reset button.
I hope this helps.
Exact same problem here. It worked about 1 out of 5 times for me yesterday morning. Today I haven't been able to login to Game Center sandbox even once (using the same code you posted).
edit: I changed the deployment target to 3.0 "Project - Edit Active Target - iOS Deployment Target"
Then I was able to select 4.1 simulator for my active executable and I can login and everything works. Something with the 4.2 sandbox I guess...
精彩评论