游戏中心处理失败的成就提交? [英] Game Center- handling failed achievement submissions?

查看:124
本文介绍了游戏中心处理失败的成就提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一般都是游戏中心@游戏中的菜鸟。我正在制作我的第二个游戏并实施游戏中心。

Im a noob in game center @ games generally. Im making my second game now and implemented the game center.

如果互联网可用,没有问题,一切正常。
但是刚才我故意让互联网无法访问,当我获得成就时,显然它没有注册到游戏中心的成就。

If the internet is available, there is no problem, everything works well. But just now I purposely make the internet unreachable, and when I get an achievement, obviously it does not register to the Game Center's Achievement.

如何以及什么是处理这个问题的最佳方法是什么?

How and what's the best way to handle this issue?

谢谢....

推荐答案

你可以添加 GKAchievement 无法注册到数组然后在返回连接时重新发送它们的对象。您还应该考虑将该数组提交给持久存储,以防您的应用在有机会发送这些成就之前终止。在完成处理程序中尝试此操作:

You could add the GKAchievement objects that fail to register to an array and then resend them when you get back connectivity. You should also consider committing that array to persistent storage, in case your app terminates before it has a chance to send those achievements. Try this in your completion handler:

// Load or create array of leftover achievements
if (achievementsToReport == nil) {
    achievementsToReport = [[NSKeyedUnarchiver unarchiveObjectWithFile:pathForFile(kAchievementsToReportFilename)] retain];
    if (achievementsToReport == nil) {
        achievementsToReport = [[NSMutableArray array] retain];
    }
}

@synchronized(achievementsToReport) {
    if(error == nil)
    {
        // Achievement reporting succeded

        // Resend any leftover achievements
        BOOL leftoverAchievementReported = NO;
        while ([achievementsToReport count] != 0) {
            [self resendAchievement:[achievementsToReport lastObject]];
            [achievementsToReport removeLastObject];
            leftoverAchievementReported = YES;
        }

        // Commit leftover achievements to persistent storage
        if (leftoverAchievementReported == YES) {
            [NSKeyedArchiver archiveRootObject:achievementsToReport toFile:pathForFile(kAchievementsToReportFilename)];
        }
    }
    else
    {
        // Achievement reporting failed
        [achievementsToReport addObject:theAchievement];
        [NSKeyedArchiver archiveRootObject:achievementsToReport toFile:pathForFile(kAchievementsToReportFilename)];
    }
}

希望这有帮助。

这篇关于游戏中心处理失败的成就提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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