私は iOS が初めてで、楽しいターンベースの iOS ゲームを書こうとしています。現在、ローカル ユーザーを認証しようとしていますが、このコードがビルドされている間 (保持サイクルの警告はありますが)、常に GameCenter での認証に失敗します。
// Authenticate the local user.
- (void)authenticateLocalUser
{
if (!gameCenterAvailable) return;
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error)
{
//[localPlayer authenticateWithCompletionHandler:^(NSError *error) { OLD CODE!
if (localPlayer.isAuthenticated)
{
// Do some stuff.
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"NOT AUTHORISED"
message:@"YOUR'RE NOT LOGGED INTO GC."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
)];
}
私の古いコードはまだ動作しますが、iOS6 で減価償却されました:
NSLog(@"Authenticating local user...");
if ([GKLocalPlayer localPlayer].authenticated == NO)
{
[[GKLocalPlayer localPlayer]
authenticateWithCompletionHandler:nil];
}
else
{
NSLog(@"Already authenticated!");
}
助言がありますか?