1

I've followed a few tutorials & Apple documentation on authenticating the local player for Game Center functionality using Objective C. Currently, our beta version has a functioning Game Center authentication for leaderboards. However, it seems that something is wrong with the authentication for achievements, because none of our achievements are coming across from iTunes Connect. From ViewController.m, the first authentication occurs as shown below:

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(showAuthenticationViewController)
 name:PresentAuthenticationViewController
 object:nil];

[[GameKitHelper sharedGameKitHelper] authenticateLocalPlayer];
}

- (void)showAuthenticationViewController
{
GameKitHelper *gameKitHelper = [GameKitHelper sharedGameKitHelper];
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: gameKitHelper.authenticationViewController animated:YES completion:nil]; }

Within GameKitHelper, the next authentication step occurs:

- (void)authenticateLocalPlayer
{
//1
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
    //3
    [self setLastError:error];

    if(viewController != nil) {
        //4
        [self setAuthenticationViewController:viewController];
    } else if([GKLocalPlayer localPlayer].isAuthenticated) {
        //5
        _enableGameCenter = YES;
        NSLog(@"Successful");
    } else {
        //6
        _enableGameCenter = NO;
        NSLog(@"Failure");
    }
  };
}

When loading achievements, the following function is used:

-(void)achievementLoad {
if (_enableGameCenter) {
    [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
        if (error != nil) {
            NSLog(@"Error in loading achievements.");
        }
        if (achievements != nil) {
            //Process achievements.
            for (GKAchievement *temp in achievements) {
                //temp
                [[GameKitHelper sharedGameKitHelper].achievementsDictionary setObject:temp forKey:temp.identifier];
                //[_achievementsDictionary setObject:temp forKey:temp.identifier];
            }
            NSLog(@"Achievements Retrievemented");
        }
    }];
  } else {
    NSLog(@"Achievements not loaded");
  }
}

When attempting to retrieve achievements, the game will always report "Error Code 6: Player not authenticated" (error != nil is true). Then, when I try to utilize the achievements dictionary, it's set as nil, which doesn't make sense.

I've got iTunes Connect info active for Game Center, and I've logged in with a sandbox account. Is there anything else that I'm doing wrong?

Any help would be much appreciated. Thanks!

1 Answers1

0
  1. Make sure on developer.apple.com, under identifiers, check your App, validate "Game Center is on".
  2. In Xcode make sure in your Target under Capabilities make sure Game Center Switch is on.
  3. Make sure you are including GameKit.framework (Build Phases, Link Binary with Library).
  4. In iTunes Connect, for your App, make sure the Version numbers are the same in your app and in iTunes connect.
  5. In iTunes Connect in your App Version (pre-submission), make sure the Game center button is on for the version, and you have added the Leaderboards / Achievements in the App Version screen (click the +).
  6. Make sure your iOS Device is actually logged into Game Center (logout and log back in to be sure).
Danoli3
  • 3,203
  • 3
  • 24
  • 35