我在 ios 7 上,使用以下代码:
-(IBAction)authenticateLocalPlayerWithViewController
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
__weak GKLocalPlayer *blockLocalPlayer = localPlayer;
localPlayer.authenticateHandler = ^(UIViewController *receivedViewController, NSError *error){
if (receivedViewController != nil)
{
[self presentViewController:receivedViewController animated:YES completion:nil];
} else if (blockLocalPlayer.isAuthenticated) {
signinButton.hidden = YES;
leaderboardButton.alpha = 1.0;
leaderboardButton.enabled = YES;
achievementsButton.alpha = 1.0;
achievementsButton.enabled = YES;
NSString *identifier;
[self reportAchievement1Identifier:identifier percentComplete:((interactiveHighscore/10000)*100.0)];
[self reportAchievement2Identifier:identifier percentComplete:((interactiveHighscore/100000)*100.0)];
[self reportAchievement3Identifier:identifier percentComplete:((interactiveHighscore/1000000)*100.0)];
[self reportAchievement4Identifier:identifier percentComplete:((interactiveHighscore/100000000)*100.0)];
[self reportAchievement5Identifier:identifier percentComplete:((allCoins/100000)*100.0)];
[self submitMyInteractiveScore];
[self submitMyNormalScore];
BOOL isRunMoreThanOnceGC = [[NSUserDefaults standardUserDefaults] boolForKey:@"isRunMoreThanOnceGC"];
if (!isRunMoreThanOnceGC) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Game Center Sign In Gift"
message:@"Thanks for signing in with game center here is 50 Coins."
delegate:nil
cancelButtonTitle:@"Thanks!."
otherButtonTitles:nil];
[alert show];
allCoins = [[NSUserDefaults standardUserDefaults] integerForKey:@"allCoins"];
allCoins += 50;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isRunMoreThanOnceGC"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
} else {
signinButton.hidden = NO;
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Game Center Not Available"
message:@"Uh Oh! Seems there was an error trying to sign in for Game Center. Try logging in through the Game Center app."
delegate:nil
cancelButtonTitle:@"Ok, Thanks."
otherButtonTitles:nil];
[alert show];
}
NSLog(@"Error: %d", [error code]);
};
}
我正在尝试对用户进行身份验证。首先在根控制器的 viewDidLoad 上,我用这个来调用它:
//get game center
LeaderboardsViewController *LVC = [[LeaderboardsViewController alloc] init];
[LVC authenticateLocalPlayerWithViewController];
然后我得到这个:
错误:0 警告:尝试显示不在窗口层次结构中的视图!
所以我尝试按下 gamecenterviewcontroller 类中的按钮(这就是验证方法所在的位置),但我什么也没得到。日志中没有任何内容,也没有出现任何内容....
运行 ios 7 GM 构建。
非常感谢!