Video hosted by Apple at devstreaming-cdn.apple.com

Configure player

Close

WWDC Index does not host video files

If you have access to video files, you can configure a URL pattern to be used in a video player.

URL pattern

preview

Use any of these variables in your URL pattern, the pattern is stored in your browsers' local storage.

$id
ID of session: wwdc2012-516
$eventId
ID of event: wwdc2012
$eventContentId
ID of session without event part: 516
$eventShortId
Shortened ID of event: wwdc12
$year
Year of session: 2012
$extension
Extension of original filename: mov
$filenameAlmostEvery
Filename from "(Almost) Every..." gist: [2012] [Session 516] Integrating...

WWDC12 • Session 516

Integrating Your Games with Game Center

Graphics, Media, and Games • iOS, OS X • 56:46

Competition and reward is central to the social gaming experience. See how to adopt Game Center in your games and learn how easily you can integrate leaderboards and achievements. Dive deeper into challenges to enhance competition among friends in any game. Explore the details of game groups and see exactly how to share Game Center data between related games — free and paid, standard and HD, iOS and OS X.

Speakers: Megan Gardner, Dan Kurtz

Unlisted on Apple Developer site

Downloads from Apple

HD Video (244.5 MB)

Transcript

This transcript was generated using Whisper, it has known transcription errors. We are working on an improved version.

Good afternoon, everybody. My name is Dan Kurtz. I'm an iOS engineer on the Game Center team here at Apple, and I'm here to talk to you about integrating your game with Game Center. So let's get right down to it. What is Game Center? Well, Game Center is a gaming platform that allows players to track their progress in your games as they're playing them, as well as connect with their other Game Center friends through your games.

Game Center is built upon three fundamental pillars that make up the platform: players, Scores and achievements. Now, some of you might be new to the Game Center platform and that's maybe why you're here today, but I bet you that these are all familiar concepts for you already. I mean, these are terms that have been within our gaming lexicon for a very long time now.

And I suppose that there might be some of you out there today that when you think about players, scores, and achievements and how it relates to your game's development, you might have a dev cycle that looks something like this. That is, you make your game first, and that's from your game design document, pen to paper, to arguing with your level designers and making your engine and all those things. And then your second step, which might be your last step, is to sort of shellack on this code that's for player authentication for whatever service and submitting scores and maybe trying to drum up ideas of what might be a good achievement for your game.

Well, again, that may be what some of you think and feel when it comes to player scores and achievements. But I play a lot of games. More than I want to admit in front of my boss here today. But for the really good games out there on the App Store, the ones that use Game Center and player scores and achievements to make a really special experience, I think I've got it figured out. I believe I know the reason that makes these games so successful.

You guys flip the script. You don't end with players' scores and achievements. You begin with them. Now, let me give you an example. If I am running through the ruins of a lost civilization, right, and I am passing way farther than I've ever run before, and I'm pretty sure I'm better than my friends as well, it would be okay at the end of the game to just show a leaderboard showing how I compare against my friends.

But you know what's really cool? What's really awesome is when I am passing the names of my friends as I am running through this level. It gives me this visceral, interconnected experience. Even though it's a single-player game, it's almost as if I'm playing against my friends right there. That's just one example of the many of how flipping the script starting with players' scores and achievements could really make your game great.

So how are we going to get from here to there? How is everybody here going to get on the train of starting your game design at this step? Well, today I'm going to talk to you more in depth about these three fundamental pillars of Game Center: players, scores, and achievements. I'm also going to talk about some new features that they introduced yesterday as well as at the keynote, that being challenges and game groups.

And along the way, I'll be giving you ideas for new possibilities that you can take and turn your game into an even brand new experience, really make your game sing, both with pre-existing features of Game Center and these new features that I'm really excited to talk to you about today. So we've got a lot of stuff to cover. Let's dive right into it. Let's get on with the very first pillar of Game Center: players.

Let's not talk about just players in the abstract, though, right? Let's talk about an actual Game Center player. Let's talk about Eunice. Eunice, like I said, is a Game Center player. She created a Game Center account within the iOS app or soon to be the Mountain Lion app.

And along with her account, she has uploaded a player photo as well as designated a player Elias. This is gone doe. It's Leet speak. I'm terrible at reading it. But when she logs into your game, she's going to expect to be able to submit scores, earn achievements. But don't forget, Eunice has also got friends. And whether your game's single player or multiplayer, she's looking to connect with those friends in new and interesting ways to really make your game fun.

So in the Game Kit platform, that is, or I mean the Game Kit framework, that is the framework you use in order to communicate with the Game Center platform, we call Eunice, the current player who's playing your game on her device, the GK local player. But there's a problem here. When your game starts up, before you do anything else, you have no idea who she is.

You don't know what her photo looks like, you don't have her alias, you can't even inspect her friend graph, let alone submit scores and achievements. And it's because she's not authenticated for Game Center for your game yet. And authentication is the very first step you need to take in order to unlock these Game Center features. So let's take a look at how authentication works. It's a very simple two-step process. Step one, you just make an authenticate call to the Game Center platform.

Then Game Center is going to do some work in the background. And asynchronously, we're going to call you back with the result of that authenticate call. And 95% of the time or so, that just results in, on your game screen, a little welcome back banner ticking down at the top of the screen that says Game Center is ready.

You can start submitting scores and achievements. And that's going to be the first step you need to take in order to unlock these Game Center features. But for the rare case, you lucky few out there who have a player who isn't currently logged into their Game Center account, we present a view controller that asks the player to log into Game Center to use all these great features that we provide to you.

Now this callback, it doesn't just get called when you call authenticate. We automatically make a callback to you in other cases as well. You don't have to worry about it, but I just want to bring it up front. So let's take a look at all the cases that we are making this callback to you, telling you whether the current player is authenticated or not.

First, just like I mentioned, upon authenticate, when you call this to Game Center, we will call you back then. But in the case of multitasking, when your game has been brought back to the foreground, automatically we're going to call you back then as well. As well as, if the current player isn't signed in and you prevent a login view controller to them and they press that sign in button or any button on that screen, we'll call you back then as well. So this login view controller, for veterans out in the crowd who have used Game Center before, you probably know what I'm talking about. But I want you to actually listen up here because this is a new feature for iOS 6 that's really important for your players.

Before iOS 6, we sort of took the timing of presenting this log-in view controller, if it needed to be shown, upon ourselves. We did not give you, the developer, full control as to when would be a good time to present this view controller. And I bet you, as fantastic game designers, could probably tell where this runs into problems.

If you've got a ditch jumper game, right, and the player has to press a jump button to jump over every ditch, and we just happen to present that view controller right before a big ditch, what happens? The player falls in a ditch, right? And nobody wants to fall in a ditch.

So now with iOS 6, we let you present this view controller when you see fit. We give you control so that you can pause your game, manage your game state, and present the view controller, get the player logged in, let them start playing your game again safely so they don't fall in that ditch.

So let's take a look at some code as to actually do authentication. Making the call, being the very first step, this is how you do it. You notice here that we're doing an application did finish launching with options. Now, this is the very first bit of code that is going to be executed within your game when it starts up anew.

So since authentication is the very first step you need to take in order to unlock Game Center features, we really recommend that this is the place that you run the authenticate call. Now, it's very simple. All you need to do is get a shared instance of the GK local player object.

You set up the authentication handler. That's step two. We'll get on to what that means in a moment. Then you call Authenticate on that local player. That's it. You've now just made a call to Game Center, and we're going to get back to you through this authentication handler. So let's take a look at step two: handling that callback.

[Transcript missing]

All else fails, authentication failed. The current player is not logged into Game Center, so you need to present a graceful fallback. Just disable Game Center features. Don't try inspecting the friend graph. Don't try submitting scores and achievements on the player's behalf. Let the players play your game. Let them have some fun.

So that's fantastic. You know, we've gone through the three steps, but what happens if authentication fails and you don't know why? Well, that's what this NSError object is all about. It tells you why authentication happened to fail. And there are two common points where authentication can fail, amongst others, but these are the ones I want to focus on right now.

The first is GKErrorCancelled. All this means is that if you presented a login view controller and the player pressed that cancel button, that's the result that you get. Or, if the player has opted out of using the Game Center platform altogether, outside of your game or within your game, then you're going to get that same error as well. They mean the same thing.

The second error is a bit mysteriously named, and I hear a lot of questions about this from new Game Center developers. It's this GK error, game unrecognized error. All this is is an iTunes Connect configuration issue. It means that you haven't clicked this button in iTunes Connect that says "Enable Game Center features." If you click this button, this error will go away. But if you've got a game that's set up for Game Center already and you create a new version of that game in iTunes Connect, you need to make sure that you're clicking this button as well in order to avoid any unforeseen errors.

So that's fantastic. We have logged the player in. That's the first step we need to take in order to use all these great Game Center features. But since authentication is the very first thing that you need to do, it's really an issue of importance to make a good first impression on your players.

You want to be able to get your players logged in and authenticated with Game Center right away so they can start having fun, right? Well, like I said, I play a lot of games, and once in a while, when I download a new game that I'm really excited about playing, sometimes I see an alert that looks something like this. This "Use Game Center. Do you want to use Game Center for this game or not? OK and cancel, or maybe OK and disable." And I am telling you today, if you've got code like this in your game, you need to take it out. The reason is twofold.

For one, from a usability perspective, it's confusing to the user. Now, what do I mean by that? Consider Eunice, who has just created a Game Center account, right? And she's logged into Game Center on her device. So she's logged into Game Center, she opens up your game, and you present this dialogue asking her, "Do you want to use Game Center or not?" She presses "No." Does that mean that you've disabled Game Center across your device? Is it just for the game? Are there gameplay consequences? Who is she to know? And if she presses "OK," well, all that means is that you've made her press a button again that she already pressed before she got to the game. So you're really just getting in her way.

The second reason, though, is that with this alert, you were writing checks that you cannot cache. Functionally, this alert cannot work in all cases. Consider the case where Eunice has already opted out of Game Center altogether. Outside of your game, she's canceled using Game Center, and she has turned it off on her device. And you ask her, do you want to use Game Center or not? Well, if she clicks OK, what's going to happen? Nothing.

There is no possible way that you can re-enable Game Center features for the current local player if they've opted out of using Game Center outside of your game. So again, if you've got a menu like this, or if you're thinking of putting something like that in, take it out. Your game's not like menu commando. It's about having fun. You just want your players to log into your game and start playing. See that little welcome back banner, and get on with having fun.

So again, authentication is the very first step you need to take to use Game Center features. It's an asynchronous process. Now, I'm just singling this out here because asynchronicity is a common trait amongst the GameKit framework API. And if authentication happens to fail, provide a graceful fallback and let players start playing your game as soon as possible with Game Center features disabled. But along that same line, you want to let your players play your game as soon as possible, right? So avoid these extra dialogues that don't really do what you may be conveying to the player. Just take them out, let players log in, and let them start playing.

So we've got players logged into your game. You are now able to use these features. So let's get on to the second and third fundamental pillars of Game Center — scores and achievements. Now, in GameKit, scores and achievements are represented by the GK score class and the GK achievement class. So let's take a look at some of the fundamental properties that define GK score and GK achievement objects. First up is GK score.

Now, GK score has three fundamental properties that define it. The first is an NSString category. This just means which leaderboard this score is for. And you've defined this string up on iTunes Connect. The second is an int64 value. Now, whether your game has a leaderboard for points, gems, minutes and seconds or what have you, under the hood, it's all the same to GameKit.

It's an int64 type. It's just really the score. And thirdly, very important but often overlooked, is this 64-bit unsigned property for context. This is your personal scratch space that you could do anything you want. We suggest that when you're submitting scores, you stuff into the context gameplay relevant data.

So if it happened to matter that the current ship was blue when this score was made, set blue into that context. And it will be there when you receive the score on a querying end. So for GK achievement, it has two fundamental properties that make it up. The first, similar to a category for score, is the NSString identifier property. This just links the achievement for a certain achievement you've defined on iTunes Connect.

Second is a double percent complete. So achievements aren't a binary thing. It's not I earned this or I didn't earn this. You can let your players gradually earn achievements as well. So if your game has four hidden gems and you want to make that an achievement to find all four hidden gems, you could submit 25%, 50%, 75%, 100% for completion states.

So let's take a look at actually writing code to submit achievements for the current player. For achievements, all you need to do is create your GKEachievement object. You init it with the appropriate identifier that you've defined on iTunes Connect. You set the percent complete. In this case, the achievement is totally earned. And then you call report achievement with completion handler.

Barring any error, when this callback is made, that means the achievement has been successfully posted to Game Center for the user. Now, for scores, it's very similar. You just create a GK score object and knit it with the appropriate category that you've defined on iTunes Connect. You set your value. In this case, it's 300 points, seconds, whatever it may be.

And you set any appropriate gameplay context. Then you report the score with a completion handler. Just like an achievement, when this callback is made, barring any errors, that score is now successfully posted to the leaderboard that that score is for. So this context, right? I mentioned it a little bit before, but again, this is whatever matters about that score and how it was earned in your game.

So again, if it's a racing game, right, like some space battle racing game, and the current ship was blue, and that matters as to how this score was earned, well, stuff the color in there. Or let's say the reason why she got around the track in 300 seconds was because her engine was so fast that normal players can't really get. Well, stuff the engine in there. Or maybe it's the weapon system that let her get 300 points blasting away enemies as she was racing around the track. It's really whatever you want.

And since it's 64 bits... Well, this is a huge number space, right? So you could use that to encode URLs that are pointing to entire replay data showing how the player just earned that score. We're going to be touching on this a little bit later as well, and I think you saw it in Jeff's talk yesterday, as well as with the half brick guys on Jetpack Joyride. This is something that we're really excited about. So I urge you to think up with some great ideas of how you can use context with scores.

So the elephant in the room, right? This NSError. Barring any errors, your scores and achievements will be successfully completed. Well, provided your players successfully authenticated into Game Center and the category or identifier you're using matches up with what is defined in iTunes Connect, You will not receive any errors from us.

Now, prior to iOS 5, we also tended to give you back errors in the case of network connectivity issues. So if the current device happened to fall offline, we would give you a network error, and we would ask you to cache your scores and achievements and resubmit them at a later date.

Now with iOS 5, because this is sort of a troublesome process for you guys to take, it became unnecessary because we introduced a small feature called Store and Forward, which took care of any network connectivity issues transparently. And if the device happened to be offline, we would store those scores and achievements and submit them once connectivity was reached again, which really made any of this old code for iOS 4 devices of caching and resubmitting totally unnecessary.

Now with iOS 6, I am telling you that if you have this caching and resubmitting code in your game, to take it out, because it's fundamentally incompatible with Game Center for iOS 6. More specifically, it's fundamentally incompatible with challenges. So if you happen to have some sort of resubmission code that looks like this — maybe it's that your application did finish launching after an authenticate, something like that — the Sync Game Center scores and achievements or Force Resync Game Center achievements, take it out. You don't need to worry about it. You don't need to sweat the small stuff because we've got it covered for you anyway with Store and Forward as of iOS 5.

So that's fantastic. We've now been getting a player logged in. They're submitting their scores, they're earning achievements, and they could open up the Game Center app right now and see how they're doing within your game. But you probably want to let players see how they're doing and compare their scores and achievements with friends within your game so they can keep playing it, right? Well, we provide you that ability within iOS 6 and what we call the unified experience. With just a few lines of code, you can let players see their scores, see their achievements, even see the challenges they've received from friends. Very little work.

So the unified experience is provided by this class, GK Game Center View Controller. And as I mentioned, it provides a unified view of everything Game Center related to your game. So you see here in our game Crush, we have a leaderboards and achievements button. If I were to happen to tap that leaderboards button here, up pops the GK Game Center View Controller.

You'll see at the top of the screen, players can rate your game right in the app store or like it on Facebook, as well as they can look at whatever scores they've earned in your game or achievements or challenges they've received from friends. And what this also means is that you are future-proofed. If we add more features in the future and we drop it into the GK Game Center View Controller, you don't need to do anything extra in order to have those features right within your game.

So what's the code that's necessary in order to display this in-game UI? Well, in this case, we've got a view controller that has some target action set up for a show UI button, right? And all we need to do is grab a shared instance of the GK Game Center view controller. We set the Game Center delegate to self. Now, this delegate's just going to be called back when the unified experience is dismissed.

We set the appropriate initial view state, and then we present the view controller just like we would any other. Now this view state actually allows you to have some customizability about what context this unified experience starts with. So let me be a little bit more specific. If you wanted to start by showing the player all the achievements they've earned in your game because you've got an achievement button, you can do that by setting the view state to the view state for achievements or for the challenges that they've received. Even for leaderboards, but with leaderboards, we give you even more fine-grained control over which leaderboard for what time you want to display. And that's with only two extra lines of code.

In this case, we're going to show a leaderboard that has all the scores earned for today for level one. So we set the view state to the view state for leaderboard. We set the leaderboard time scope to the time scope for today. We also set the leaderboard category to the leaderboard that we want to start off with. In this case, it's level one. The string matches up with what you've got on iTunes Connect. And away you go. Now, when they tap that leaderboard button for level one, up pops all the top scores for today for level one.

Now, the unified experience has one feature that we're very excited about called sharing. And we allow you through the unified experience or allow your players to share their scores and achievements with friends over any social network that we support. So that's Twitter, Facebook, even messages or mail, and even copying it to the clipboard if so need be.

But that's great. The unified experience allows players to do that for free to you. But what if you wanted to actually let them share their scores and achievements immediately within your game? I mean, you know your game best, so you probably know what screen would be a great screen to let players tweet it to the world, right? So let's say a player just beat level one, and they've got a score of 500 points, and they just earned an achievement, and they want to tweet to the world. So we provide you the ability to bring up what's called the UI Activity View Controller to let the player share their score through any of these services and more.

Now, this again is done through the UI Activity View Controller, and this class, this object, handles transport across any different social service. You don't need to write code to allow submission of your scores and achievements to Facebook and Twitter and all that. We cover that for you with this object.

And Game Center with iOS 6 provides direct drop-in support for score and achievement sharing. So if the player were to tap the Twitter button here, up would pop a tweet sheet that has preformatted, localized text for the current player saying, check out my score on the score leaderboard with a URL that's attached to that Twitter message. So when they press send, this score tweet is sent to the world, letting players, other possible players of your game, discover your game.

So to do this in code, it's very straightforward. In the case of sharing a score, you just need to get a reference to a GK score object that you wish to share. You set up the UI Activity View Controller, and you pass in the score object through the init method.

You set up your completion handler for this view controller. Now, the completion handler is called when the sharing action has been completed, so all you need to do is dismiss the view controller at that time. And finally, you just present the view controller, just like you would any other view controller. And for achievements, it is nearly exactly the same thing. The only thing that's different is instead of creating a score object and passing into the init method, it's the achievement object that you're passing in. Everything else is dead simple, exactly the same.

So for some things for you to keep in mind with score and achievement submissions as well as viewing, when it comes to submitting scores, think about context. You've seen some examples already, and we'll touch on some examples later about how context can really make your game special. I mean, this is your way of adding your signature to every score. It's whatever is special about your game can be imprinted on every score your game's submitting.

As well as if you're submitting scores and achievements and you've got this legacy code from iOS 4 and before of archiving and resubmitting these scores and achievements, make sure you take it out. We've got it covered for you so you don't need to worry about it, and it will make your game 100% compatible with challenges on day one of iOS 6's release. And if you want to let your players view your leaderboards as well as your achievements and challenges for your game, you can do that with just a few lines of code through the unified experience.

So we've got players logged in, they're submitting scores, they're submitting achievements, they're tweeting it to their friends and their moms. They are having a blast with your game. But recall this slide. It doesn't end here. This is not the ending. This really is the beginning. How can we use players' scores and achievements to make your game truly special and really sing? Let's take a look at an example. Let's all remember Eunice right here. And Eunice is earning scores now because of the great code you just wrote, as well as earning achievements in your game. But recall Eunice has friends.

She has a lot of friends, and Eunice is a pretty hardcore gamer. And she's playing this new game that she's all excited about, and she gets 500 points. She knows Jessica here is also playing that game, but she hasn't really seen Jessica post a score that's nearly as high as this, right? So normally, players are excited about a game and they know that they just did better than their friends. What happens? Maybe they call each other on the phone and say, hey, I just, you know, did better than you. I bet you can't beat that.

Wouldn't it be great if we could take advantage of this within your game's gameplay and turn it into an entirely new mode of game development and game, you know, a way of having a fun time within your game? With iOS 6 and Game Center, you can do that with challenges. So you've heard about challenges a lot already. I want to explain exactly how they work and how players will use them to play your game in new ways.

So recall Eunice is playing this game Crush, right? And she just beats level one with a score of 500. And she knows that Jessica might not be doing as well as she is in Crush, so she chooses to challenge Jessica to beat her score of 500 points. So she sends a challenge over to Jessica.

And right then, Jessica's device gets a drop-in notification banner, both on the home screen of her iPod Touch as well as within your game, saying Eunice has just challenged you to beat her score of 500. So let's say Jessica is on the home screen like she is right now, and she taps that notification banner. That's going to start up Crush. And Jessica's actually a little bit better than Eunice had expected. She beats level one, getting a score of 600.

Well, 600 is greater than or equal to 500 points, which means that Jessica has just beaten the challenge. So right then, both Eunice and Jessica get a push notification saying, "Jessica just beat this challenge." And since this is a score challenge, Jessica has automatically sent a new challenge to Eunice telling her to beat her score of 600 points.

Now, I've been talking about scores and score challenges and auto-submission and all that sort of stuff. But it's not just scores that challenge Eunice. It's what the challenges are for. We support both score challenges and achievement challenges. And what's more is if your game supports leaderboards and achievements for Game Center, on day one of iOS 6's release, it will automatically, out of the box, support challenge play. Players will be able to send challenges to each other through the Game Center app to compete with beating scores and earning new achievements. But before I get into all the who's, why's, what's, how's, and how's, I want to talk about a couple of things.

So, first of all, I want to talk about how this all works. Megan's here to actually show you a game that we made called Crush, which you've seen in the screenshots already, that takes advantage of both automatic challenge play and extra API that we provide to you in order to customize the challenge experience. So, Megan, take it away.

Thanks, Dan. So Dan has explained to you what challenges are, and I'm going to help you experience them. So I'm also friends with Eunice, and we have been playing this great new game, Crush. And oh, look, it looks like Eunice has actually just challenged me to beat her score of 700 points. And as you saw, it's just a notification. So if we just go into Notification Center, you can just tap on that notification, and we'll launch directly into Crush. Because I've already downloaded Crush because I've been playing around with it a little bit.

And Crush has this great challenge mode. And since we're doing a challenge, why don't we tap on that? And Crush has actually been written to use the challenge API to remind us who has challenged us, Eunice, as well as she's actually sent us a message, and it is also reminding us the score that we need to beat to beat her challenge.

So why don't we play this game? So this is just a pretty simple top-down space shooter, and I'm a pretty good gamer, so I'm pretty sure that I'm actually going to be able to beat 700 points pretty quick. And there we go, already over 700 points. That's awesome.

But I was actually checking out the achievements for this game earlier, and there's actually an achievement for beating level 1, which I actually haven't gotten around to doing yet. So I'm just going to take a few more seconds here and see if I can actually just go ahead and beat level 1. And there we go. We were able to beat level 1, so we unlocked that achievement.

We got a score of 4,600 points. Which is well over the 700 points that we needed to get in order to beat Eunice's challenge. So we got a challenge complete. And as soon as I completed this challenge, Eunice actually got a challenge for me to beat my score of 4,600 points. And, you know, that's great and all. She's got a challenge for me. But I actually, since I just completed this achievement, I'd actually like to challenge her to complete that achievement as well. So if we just tap on this challenge, friends.

Button. We can actually send Eunice a challenge directly from within the game. So why don't we send that off to her and see if she can not only beat our score, but also beat our challenge. So that is challenges for scores as well as achievements. And those are just some of the few things that you can do to add to the interactivity of your game between your players, even in single player games. And I'm sure that you guys are going to come up with some great new ways to extend gameplay. And some really cool stuff that we haven't even thought of yet. And I can't wait to see what you guys do. Thanks. Back to Dan. Thanks a lot, Megan.

Right when the score is submitted, having beaten that challenge, Megan would have received a push notification saying, "You've just beaten Eunice's challenge." And at that point, there was custom UI that would be displayed saying, "Congratulations, you just beat the challenge." And she could have even sent an achievement challenge right back to Eunice, kind of piling it on a bit. But you guys saw, hopefully, at yesterday's games kickoff, the Jetpack Joyride demo that used challenges as well, which also shows another way that you could make custom challenge play within your game to turn any single-player or multiplayer game into a new, interconnected, friend-based experience.

So, Rekall, I talked about how challenges are free, out of the box, on day one of iOS 6's release, provided your game supports leaderboards and achievements. Well, how does that work? Well, Rekall, your game is now going to be reporting scores as well as reporting achievements to the Game Center, right? So let's say Jessica has a challenge from Eunice to beat a score of 500 points. Jessica makes it — well, you make for Jessica a report score call to Game Center for 600 points, which means that Game Center now sees that that challenge for 500 is now completed because Jessica just got 600.

So automatically, Game Center will push back to Jessica's device, telling her, "You just beat Eunice Park's challenge." Now that's fantastic, but what if you wanted to actually have in-game control of challenges? Like, let's say you want to allow players to programmatically, automatically challenge their friends within your game.

Again, I bet you all have a screen that looks like this, some sort of level complete screen, and you're showing a score and you're showing an achievement. And before we discussed about how we could allow players to share their scores and achievements, but what if you provided control for players to also, right then and there, send a challenge to their friends to beat that score, to earn that achievement as well.

Well, to do that, it's very simple, straightforward code. For sending an achievement challenge, you just need to first have the friends of the current local player that this challenge is for, as well as a message, both of which should be determined by the current local player. Then for an achievement challenge, you just create an achievement object like you would any other and knit it with the appropriate identifier. Set the percent complete to 100.

Call issue challenge to players with a message. Passing those players and the message for that challenge. Now with achievement challenges, recall I said percent complete equals 100. While achievements can be gradually earned, as far as challenges go, you can only challenge someone to fully earn an achievement, not gradually. So when you're sending an achievement challenge, you want to make sure that this percent complete property is set to 100. For scores, it's very similar.

You set up the friends who are going to receive this challenge as well as any message. And then you create your GK score object like you would any other. You init it with a category. You set the point value it's for as well as any gameplay appropriate context so you can get reference to that context when you receive the challenge on the other side. Then you call issue challenge to players message on that GK score object. And right then and there, it will be automatically sending a push notification to the receiver's device informing them that the current player has just called them out.

So that's great. We can now programmatically issue challenges to players within your game. But what about the receiving end? You recall that we displayed a notification banner on the home screen during the demo telling Megan that she just got a challenge from Unus. And when she tapped it, it launched the game with a special challenge mode for the challenge that the player just selected, right? Well, if your game is even currently running, automatically we display a similar drop-down banner telling the player that they just received a challenge. And if they select that banner, if they tap on it at the top of the screen, that will allow you to hook into an event to display custom UI to the player saying, hey, this is the challenge you just tapped.

Unus Park is telling you, let's play, and here's the score information or the achievement that you got to earn. And maybe even after that, you could put in a new gameplay mode. Based around the challenge. Really anything you wanted to do. So to hook into this selection event, this tapping of that banner, you can do that through what's called the GK Challenge Event Handler. Now, the GK Challenge Event Handler is just the call center for all challenge-related events on Game Center.

It's a singleton, and it has a delegate that you assign. It's very similar to a lot of other patterns within both Game Center and UIKit. And it handles events for reception of challenges, selecting challenges. Completing challenges. You can even customize whether those banners will be appearing in your game when challenges are received or when they're completed.

So to handle the case of the current player tapping that challenge received banner, thus they're interested in playing against that challenge, the steps you need to take are such. You set up the delegate and you override the appropriate event. So in this case, it's a challenge banner was just displayed and the user tapped on it, and you want to display some sort of custom UI and maybe even start your game in a new mode.

So to display this player's photo and maybe their name, you've got to retrieve the issuing player's name and photo. As well as, if you're going to start your game up in a new challenge-centric mode, you load any appropriate data for the score or achievement that has to do with that challenge. And then you present your custom UI and away the player goes.

So let's take a look at the code that's required for implementing this custom UI and hooking into the challenge event. First, for setting up the delegate, you'll see here that the application is going to be a little bit more complex. The application delegate is implementing the GK challenge event handler delegate protocol. Now, this could be any object that implements this protocol. We're just using it here because it's a pretty straightforward use of an example. And you'll notice application did finish launching with options.

As soon as possible, we're setting up the delegate for that shared instance of the GK challenge event handler object. Set up the delegate, and right then, you are hooked into the challenge event stream, and you will get told any time the local player got a challenge received. or they completed a challenge, or tapped a banner.

Now, in order to implement the code for the player selecting a challenge banner, we provide a method for the delegate to implement called LocalPlayerDidSelectChallenge. Now, to display that player's name, the issuing player's name in their photo, it's very straightforward. A challenge holds a reference or to the player ID for the issuing player. Now, this player ID is just a unique handle that refers to a Game Center player. And you can load the GKPlayer object with that ID, calling LoadPlayersForIdentifiers. And when this completion handler is called, you get a reference to the GKPlayer object that player ID represents.

Now, we want to load a photo, right? So you call on that GKPlayer object, load photo for size. You pass in the appropriate size. In this case, Eunice's photo is pretty big, so we're passing in GK photo size normal. And when that completion handler is called back, you just present the challenge UI that you wish to present. And you load any additional data that you wish to have as well in order to put your game into a new sort of challenge-based mode. So I keep talking about challenge-based modes and loading data. Let's take a look at what we could do here with this challenge.

Load data for challenge. Let's say the challenge that was received was a score challenge. Well, something we could do with a score challenge is score challenges contain a reference to a GK score object that was used to create it. And recall that scores have context, right? So let's say you encoded a URL holding gameplay like ghost replay data of how Eunice scored those 500 points when she challenged Jessica. Well, right here, you could load up that ghost data when Jessica selects the challenge banner so that when Jessica is playing your game and racing through the stars, Eunice's ship is right alongside with her. Now, this isn't real-time multiplayer, but it's a very similar experience.

Jessica sees Eunice calling her out the entire way, and you're just raising the bar of competition there. This is just one of many examples of what you could do with context as well as challenges and achievements in order to make your game really special and truly stand out amongst all the other games on the App Store.

So we've got issuing challenges as well as receiving and selecting those challenges. What about when a challenge is completed? Well, when a player completes a challenge, by default, we present that little banner saying you just beat so-and-so's challenge. But maybe you want to jazz it up a bit. Maybe you really want to give them a pat on the back.

And you want to show some custom UI that says, "Hey, way to go. You did a really great job. This challenge is beaten." Maybe you want to show an icon of the achievement or the score leaderboard that that challenge was for. Well, you can do this very similar to the previous example of a player selecting a challenge. You just need to implement local player did complete challenge in your challenge handler delegate.

And in the case of displaying a UI image that is based off of the score or the achievement icon, to do that, if it's a score challenge, recall, scores, score challenges have a reference to their scores. So you can look up the leaderboard icon for that score. And just the same, achievement challenges have references to the achievements that were used to send that challenge.

So you can look up in a lookup table somewhere in your game to get the icon for the achievement. And finally, you just show your completed challenge UI. You blast some particle effects, sound the trumpets, whatever you got to do in order to give your players that sense of they've done something special, and they've beaten their friends in your game.

So we've gone over two particular events that you can hook into here. When a player selects a challenge banner or when they complete a challenge on their device that they received. But we provide you other events that you can hook into here that I'm not going to get into, but I suggest you take a look at the documentation. So local player received challenge. That's when the local player received the challenge in any case. Not just tapping the banner to launch your game or within the game, but anytime they receive a challenge so you can present your own UI.

As well as when the remote player completed a challenge. So if I sent a challenge to you and you beat it, this is when I get a push notification telling me that you just beat my challenge. So you could put in some interesting stuff there as well. As well as we give you control of overriding the banner behavior. If you want to hide those Game Center banners are displayed within your game, you can turn those off at your own at your own control.

So a couple things I want you to keep in mind when it comes to challenges. We recall this slide of issuing a challenge programmatically, and we're filtering out players for the current challenge as well as having the player enter in a message. You want to make sure that the players who are receiving a challenge are ultimately decided by your current local player, as well as that message that's being attached to the challenge. You want the local player to enter that message.

Challenges are from the heart. I mean, it's a friend calling out their friend, saying, "I bet you can't do better than me." So you want to make sure that your players know which friends they're sending this challenge to and what words they're using and message they're sending when this challenge is issued.

That doesn't mean, though, that you can't, you know, push them in a direction, right? Like, let's say you've got Jessica, who just got a score of 500 points. Maybe it wouldn't make too much sense for her to challenge Ed, who got 4 billion points in your game. But for somebody like Eunice, who only got 300 points, maybe you want to present to her the option of saying, hey, here are all your friends. Eunice scored less than you, so maybe you want to challenge her. But you can challenge other people as well.

So how do we do that? How do we suggest players that the current player could issue a challenge to? We provide in the GameKit framework a GK leaderboard object. And this class allows you to query scores that were posted to any leaderboard you've set up in your game. So let's say it's a score for level one that we want to filter all lesser scores for. In this case, we just create the GK leaderboard object. You set its category to the leaderboard string you've defined in iTunes Connect.

Then you set up the player scope to be friends only. That's because challenges can only be issued to friends of the current player. And in this case, we're getting the top 100 scores from all friends for level one. Now, when you call load scores with completion handler and that completion handler is called back, you will receive an array of all scores that are for level one for friends. And here you can filter that array for any score that is less than the score that was just earned in that recent playthrough.

And finally, you present a friend picker. Let the player decide, "OK, well, it seems like Eunice scored less than me, so maybe I want to challenge her. But, you know, Ed's there as well, and he's not selected by default because he already got 4 billion points in this game, but maybe I don't think he could do it again." So let them have that final control.

One other thing I want you to keep in mind with challenges specific to achievement challenges is that by default, once a player has earned an achievement in your game, they're no longer eligible to complete a challenge for that achievement. Now, the reason is a gameplay reason. There may be achievements that you've defined within your game that don't make sense to be earned more than once. So let's say you've got an achievement for starting up the game for the first time. You can't start up a game for the first time a second time, so because of that sort of case, we've defaulted the behavior of you can't re-challenge people.

But we do provide you the ability in iTunes Connect to re-enable specific achievements, to be re-challengeable. Even if the current player has already earned that achievement, if this is set to "yes" in iTunes Connect, this "achievable more than once" option, then players will be able to challenge their friends over and over again to earn this achievement.

And on the note of achievements, I want to highlight that achievements are your in to make challenges as custom as you want. I mean, we have scores, right? And those are great. But if you want to make it so that the player has to backflip backwards through a platforming level and never dying and never pressing the turbo button, and you want players to challenge each other based on those ridiculous guidelines, be our guest. Make an achievement that has that sort of standard. And when that achievement is earned, well, a challenge could be completed.

But recall, though, that your game has limited achievements allotted to it. You can only define so many. And with the advent of game groups, you know, this is going to be a very crowded space. So if you've got achievements that maybe aren't fun or even sound something like killed 100 aliens, killed 200 aliens, killed 300, 400, however many aliens, that sounds like a leaderboard.

And you probably, when you're thinking up of these sorts of achievements, if you've got a pattern like that, maybe you should set it as a leaderboard. And if you've got a pattern like that, maybe you should set it as a leaderboard. And if you've got a pattern like that, maybe you should set it as a leaderboard. And if you've got a pattern like that, maybe you should set it as a leaderboard. So that you have more space for even more fun, replayable challenges within your game.

So challenges, again, are built in day one on iOS 6. Your game will support it if you've got leaderboards and achievements. But we provide you API to extend your game to provide custom challenge-based gameplay modes. And GK Score Context for score challenges, this is an awesome way to make any score challenge seem like a visceral, the player is right there, in-your-face experience. So I consider that you give context a second look here. And recall that challenges are a personal message, so give the issuing player of those challenges final control and say over who's going to receive the challenge and what's going to be said along with it.

And as many times as possible, if you have an achievement that would be, you know, would make sense for it to be replayable, to be challenged over and over again, then tick that box from no to yes on iTunes Connect. The more replayable achievements you have, the more fun everybody's going to have. I bet you earned that achievement once, but I don't think you could do it again.

It's that sort of gameplay, right? So that's challenges. And one more thing that I want to talk about today is something that you've heard about already. I bet a lot of you out there have different versions of your games. You might have a light version. You might have an HD version.

And now with Mountain Lion, you're going to have some sort of desktop version of your game, right? And wouldn't it be awesome if when I'm playing the light version of your game, And I score 500 points automatically on the HD version and the desktop version. Those 500 points are tracked right out of the box so that when I upgrade to the full version or when I go and buy the desktop version of your game, all my statistics are already there, providing a consistent experience. And similar for achievements. If I earn an achievement in one version of your game, all other linked games get that same achievement. Well, we allow you to do this as a mountain lion, and it's called game groups.

Now, game groups, I'm happy to tell you, requires no specific coding. You don't have to code anything. It's an iTunes Connect configuration step. And through game groups, you can group leaderboards of different versions of your game, as well as achievements. You can then, having linked leaderboards and achievements, allow your players to beat challenges on any linked game within that group ecosystem, as well as cross-version multiplayer. So that, as you saw at the keynote a few days ago, I could be playing a game.

And I could be playing a game on the iPad against a friend who's playing it on Mountain Lion. A really cool, powerful cross-platform experience that lets your game be more discoverable by everybody brings all your players together. So how do we do this? How do we go about linking your games and putting them into the same game group? Well, I'm going to go through a quick blow-by-blow here, but I do suggest that you check out the iTunes Connect session tomorrow. I'll give you the time in a minute. But let me just give you the points that you need to keep in mind when you're setting up your game.

And I'll give you the points that you need to keep in mind when you're setting up different versions of your game to take advantage of game groups. To group these games, all you need to do is, in iTunes Connect, is select one of the games that you wish to add to a group.

From there, in iTunes Connect, you'll see an option to move this game to a new group. So let's say all these three games are different versions of Crush, right? So we define a Crush group. Now we go through every leaderboard within the game. And we define a new group identifier for those leaderboards. So level one, level two, level three.

Level one gets group.level1. Similar for achievements. For every achievement in that game, we define new group identifiers for the achievements as well. So for achievement one, it's group.achievement1. And now, when we want to actually add other games to this group, we select that game. We move it to the Crush group.

And we go through any leaderboards that we want to merge into that group. So, hey, we've got this level one leaderboard. We want to link it with that other game's level one. We just give it the same group category. And now, these two games are linked for a leaderboard. Now, if you want to link a game for an achievement, per se, let's say it's a new game that you want to add to the group, you move it to that Crush group.

You take the achievement that you want to link it for. Hey, it's achievement one, so I want to link it with that original game's achievement one. Just give it the same group identifier. And now those games are linked for the achievement. And from here on out, after you've merged your leaderboards and merged your achievements, you can define new leaderboards and specify which games are eligible for that leaderboard. Similar for achievements. Maybe you want all games to be eligible for this achievement that you're defining. That's how it works.

Now, for cross-version multiplayer, to let your iPod Touch users play against your players on Mountain Lion, it's very simple as well. You select one of your games that you put into this group. And you go to View Details, Multiplayer Compatibility. I hope you're all writing this down. There's a test at the end of the session. So, no, it's, again, iTunes Connect. Take a look at it tomorrow. It'll be great. Go to Multiplayer Compatibility. You've got a lot of different versions, all the different versions of your games that are in the group.

And from here, you can specify that Crush Lite 1.1 is cross-compatible with all versions of Crush HD for multiplayer, which is also compatible with 1.01 and 2.0 of Super Crush. And it's just like that, provided you've got your network code in the background or you're using the term-based API, all these games are now compatible with each other for cross-version multiplayer.

So again, blow by blow, right? Just keep these things in mind tomorrow morning. You need to define a group ID. And from there, you can convert your leaderboards and achievements for any game into grouped leaderboards and achievements. And anytime you add a new game to that group, you just have to merge those leaderboards and achievements together.

And finally, if your game is multiplayer — oh, I'm sorry. And also, when you're defining new leaderboards and new achievements for all games in this group, you can do that just like you would any other time. And then if your game is multiplayer and you want to specify which versions of your game are compatible with each other, just do it right then.

So we've learned a ton today. We've got players authenticating, and they are talking to their friends by sending them challenges of scores and tweeting achievements to the world. And again, with challenges, there's this custom API that you can use that, while challenges are built in on day one, you can make your game really, really sing if you take advantage of this extensible API. As well as game groups to allow players of any different version of your game to play together, to track their progress across all versions, to provide a solid upgrade path to your players. A really powerful option that requires no code on your behalf.

But this was a ton of information, right? So if you need information, if you haven't been taking notes and you're going to flunk this test afterwards, talk to Alan Schafer. He's our graphics and game technologies evangelist. He's a great guy. He'll answer all your questions. We've got game center documentation online, as well as the Apple dev forums.

Now, for related sessions, before you leave, what's new in iTunes Connect for app developers? I singled out already. But if you've got a multiplayer game, tomorrow at 10:15, Christy is going to give a great talk about using the multiplayer stack in game center. And Gabe is going to be giving a talk right after that at 11:30 about building games for OS X Mountain Lion and showing how easy, how identical this framework is across platforms. What's new? Really looking forward to seeing you guys. Thank you so much for coming out today. I can't wait to see your games. Thanks.