1

Just finished my first iOS game (mostly). Its all ready to go, just need to link in Game Center. This however, is proving to be ...annoying. My App is all registered on iTunes Connect, and all the Game Center code is taken directly from Apple. So why is NONE of this working?

First: authentication always fails;

 GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

 localPlayer.authenticateHandler = ^(UIViewController *loginVC, NSError *error) {
    if ([GKLocalPlayer localPlayer].authenticated) {
        // authentication successful   
    }
    else if (loginVC) {
        // player not logged in yet, present the vc
        [self presentViewController:loginVC animated:YES completion:nil];
    }
    else {
        // authentication failed
    }
};

With error "The requested operation has been cancelled"

As a corollary, trying to present a game center vc in the future yeilds a "Player is not signed in message"

Second: this

GKScore *score = [[GKScore alloc] init];
if (score) {
    score.value = self->selectedScore;
    NSArray* scoreArray = [[NSArray alloc]initWithObjects:score, nil];
    //score.category = @"High Scores";

    UIActivityViewController *avc = [[UIActivityViewController alloc]
                                     initWithActivityItems:scoreArray applicationActivities:nil];
    avc.completionHandler = ^(NSString *activityType, BOOL completed) {
        if (completed)
            [self dismissViewControllerAnimated:YES completion:nil];
    };

    if (avc)
        [self presentViewController:avc animated:YES completion:nil];
}

yeilds a 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

What am I fundamentally doing wrong? Thanks to anyone who can offer any help.

4

1 に答える 1

3

Try to log out/in in the Game Center application with your test user account.
Check this answer: https://stackoverflow.com/a/4420457/89364

于 2012-09-24T06:42:20.383 に答える