【问题标题】:Problems With Game Center游戏中心的问题
【发布时间】:2012-09-24 00:52:03
【问题描述】:

刚刚完成我的第一个 iOS 游戏(大部分)。一切准备就绪,只需在游戏中心链接即可。然而,这被证明是……烦人的。我的应用程序都在 iTunes Connect 上注册,所有 Game Center 代码都直接取自 Apple。那么为什么这些都不起作用呢?

首先:认证总是失败;

 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
    }
};

出现错误“请求的操作已被取消”

作为推论,尝试在未来展示游戏中心 vc 会产生“玩家未登录消息”

第二个:这个

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];
}

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

我从根本上做错了什么?感谢任何可以提供任何帮助的人。

【问题讨论】:

  • 您在第一个代码块中似乎有一个复制错误,请您更正一下吗?
  • 哎呀抱歉。固定的!感谢提醒

标签: iphone objective-c ios game-center ios6


【解决方案1】:

尝试使用您的测试用户帐户在 Game Center 应用程序中注销/登录。
检查这个答案:https://stackoverflow.com/a/4420457/89364

【讨论】:

  • 是的,奇怪的是它起作用了。更奇怪的是为什么我从没想过这样做。不过,感谢您抽出宝贵时间阅读/回复!赞赏!
猜你喜欢
  • 2011-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-06
  • 2011-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多