Offline Game Center Reporting

Saturday, 2012-09-29; 14:35:09

If you’re developing a game in iOS and implementing Game Center support, you may have come across this paragraph in Apple’s Game Center Programming Guide:

Whether reporting achievement progress on a single achievement or multiple achievements at once, your game rarely needs to do anything specific when an error occurs. If an error occurs, such as when a network is not available, Game Kit automatically resends the data at an appropriate time.

This is a lie.

One of my pet peeves about Game Center when it was first introduced was that achievements and scores earned offline were never properly transmitted to Game Center. When iOS 4 was the current major version, the above excerpt in the documentation instead said something like, “if an error occurs, you must save the achievement yourself for transmission at a later date”.

Once iOS 5 came out, the current language in the guide was added in. Hooray! Game Center scores and achievements would be reported across all Game Center applications even when offline!

Unfortunately, this isn’t the case in practice.

I have an iPod touch. Frequently, I’m at home or some place that has Wi-Fi, but sometimes I’m not. Often, this happens when I’m on the train going somewhere, and I have 30 minutes or so to kill. So I open up my favorite Game Center-enabled game, and play for a bit. But it’s so annoying when you get a really good score or an incredibly hard achievement, because, in practice, automatic offline Game Center reporting never works.

I recently verified this problem on both iOS 5 and iOS 6. My iPod touch is a 3rd-generation device and iOS 6 doesn’t support it. I tested this supposed Game Center functionality by turning off Wi-Fi, getting a high score in Super Hexagon, and then turning Wi-Fi back on. Nothing I could do would cause the new high score to be correctly reported to Game Center. (I messed around with both the Super Hexagon app and the Game Center app itself.)

There’s a hedge in the documentation, which says that the data is resent “at an appropriate time”, but in all my use of iOS 5, I’ve never seen an offline score or achievement reported correctly. I tested iOS 6 on my iPad 3, with similar results.

It just doesn’t work. (I’ve filed a bug.)

So, how do Game Center developers fix this issue? Well, they can do what the iOS 4 Game Center Programming guide originally said: check for an error during transmission of the score or achievement, and manually resend it at an appropriate time yourself, as Game Kit said it would do.

Luckily for you, I have some spiffy code that does this all for you. Check it: Information on using this code is included in the repo. Any bug fixes, code suggestions, etc., are heartily welcomed as pull requests on GitHub, or via Twitter or e-mail.

Sakura Quick Math and Shiny Things

Please note: I wrote this code for my previous employer, Shiny Things. At the time I left the company, the iOS game was unreleased, but I was graciously allowed to open source just this part of the code so that other developers could implement offline Game Center reporting easily. Initially, I decided not to post the code, because iOS 5 had this functionality built-in, but after further use of iOS 5 and 6 and determining that this functionality was not actually working, I finally polished up the code and wrote this post.

This past week, Sakura Quick Math was released. The UI has been completely revamped since last I saw it, but, thankfully, my code to submit offline Game Center achievements is still present! So, if you’d like to test this functionality in a shipping app, go get Sakura Quick Math.

As far as I know, Sakura Quick Math is the only iOS game that correctly reports Game Center achievements and scores when they are obtained while offline.

So, many thanks to my former employer for allowing me to open source this code!

Technological Supernova   Software Development   Older   Newer   Post a Comment