向iOS 9中的GameCenter报告分数(xCode 7.1.1) [英] Reporting score to GameCenter in iOS 9 (xCode 7.1.1)

查看:119
本文介绍了向iOS 9中的GameCenter报告分数(xCode 7.1.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个完整的游戏,在提交到App Store之前我要进行整理。

So I have a finished game, which I'm just tidying up before submitting to the App Store.

由于我完成了大部分编码,所以我ve已将xCode从8.1更新到7.1.1,并将我的设备从8.1更新到iOS 9.1。

Since I finished the majority of the coding, I've updated xCode to 7.1.1 and my device to iOS 9.1 from 8.1.

我了解到的第一件事是Game Center中没有沙盒切换功能(这就是我通常总是毫无问题地使用它)

The first thing I've learnt is there's no Sandbox toggle in Game Center (which is what I've mostly always used with no problems)

现在,当我运行应用程序时,涉及到使用以下代码报告分数:

Now, when I run the application, when it comes to reporting a score using this code:

-(void)reportScore{
    GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier];
    this_score.value = gameScore;

    [GKScore reportScores:@[this_score] withCompletionHandler:^(NSError *error) {
        if (error != nil) {
            NSLog(@"%@", [error localizedDescription]);
        }
    }];
    NSLog(@"Reported to Game Center...");
}

我将此错误打印到控制台:

I get this error printed to the console:

*** Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A GKScore must specify a leaderboard.'
*** First throw call stack:
(0x184e60f48 0x199a13f80...  ...0x1000d9748... ...0x19a2628b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

其中, GKScore 必须指定排行榜 ...

which states, a GKScore must specify a leaderboard...

我很困惑,因为直到我更新到iOS 9为止,这都很好。

I'm confused, because up until I updated to iOS 9, this worked fine.

我一直在阅读有关iOS 9中沙箱合并的文章,但我不了解所有内容。

I've been reading a bunch about the merging of sandbox in iOS 9, but I don't understand all of it.

来自我可以收集什么,将其合并到真实帐户中,删除所有沙箱数据,并在真实排行榜上进行测试?我可能是错的。就像我说的那样,我不是100%。

From what I can gather, it's merged into real-life accounts, all sandbox data is deleted and testing is done on real leaderboards? I may be wrong. Like I said, I'm not 100% about this.

如何解决此问题?我不确定使用正确的术语来查找准确的资源...我已经使用Google搜索了很长时间了。

How can I solve this problem? I'm not sure of the correct terminology to find accurate resources... I've just been wildly googling for ages.

也许我需要在本地指定我的LeaderboardIdentifier?

Maybe I need to specify my LeaderboardIdentifier locally?

预先感谢。

更新

这比我想象的还要糟糕...
我尝试打开/提交到Game Center时在App Store中的所有应用现在都崩溃了??

This is even worse than I thought... All my apps that are in the App Store now crash when trying to open/submit to Game Center...?

我只想测试一下它们,因为阅读此内容 ...

I only just thought to test them since reading this...

是否有更清洁或更更新的实现Game Center的方法? / p>

Is there a cleaner or more updated method of implementing Game Center?

推荐答案

所以,我有一个解决方法……似乎正在起作用。我将在接下来的几个小时(或几天)内进行相应的更新...

So, I have a work around... that appears to be working. I will update accordingly over the next few hours (or days)...

我的预感是正确的,如果我指定了 LeaderboardIdentifier 在方法中使用字符串,现在看起来像这样:

My hunch was right, and if I specify the LeaderboardIdentifier using a string inside the method, it now looks like this:

//GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier];
GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:@"myGameLeaderboardID"];

还有方便的 NSLogs ,我的通话& 方法看起来像这样:

And with the handy NSLogs I also included, my call & method looks like this:

-(void) GameOver {
        .
        .
        .
    if(_gameCenterEnabled){
        NSLog(@"--Reporting Score to Game Center...");
        [self reportScore];
    }
}

-(void)reportScore{
    NSLog(@"--- Got to the method");
    GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:@"Enemies_Located"];
    NSLog(@"---- Alloc GKScore done");
    this_score.value = gameScore;
    NSLog(@"----- Score assigned to GKScore");

    [GKScore reportScores:@[this_score] withCompletionHandler:^(NSError *error) {
        if (error != nil) {
            NSLog(@"%@", [error localizedDescription]);
        }
    }];
    NSLog(@"Reported to Game Center...");
}

将在以下控制台中显示以下结果:

Which results in the following console print out:

2015-12-07 23:20:24.666 myGame[88.....48] Some InGame Ref: 15
2015-12-07 23:20:24.704 myGame[88.....48] --Reporting Score to Game Center...
2015-12-07 23:20:24.704 myGame[88.....48] --- Got to the method
2015-12-07 23:20:24.705 myGame[88.....48] ---- Alloc GKScore done
2015-12-07 23:20:24.705 myGame[88.....48] ----- Score assigned to GKScore
2015-12-07 23:20:24.705 myGame[88.....48] Reported to Game Center...

这绝不是解决此问题的官方方法,它在论坛中经常出现现在有很多人,因此为什么我几天都没有回答这个问题……但这似乎对我有用。请让我知道您是否也有运气,或者您知道在iOS 9上实现此功能的更好方法。

This is by no means an official way to fix this issue, which looking around forums a lot of people are now having, hence why I'm leaving this question unanswered for a few days... but it seems to be working for me. Please let me know if you have any luck with this too, or you know of a better way to implement this for iOS 9.

同时,我可能应该更新所有我的应用程序现在-_-

Mean while, I should probably update all my apps now -_-

这篇关于向iOS 9中的GameCenter报告分数(xCode 7.1.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆