Using Game Center with Unity iOS
Today I experimented with Apple's Game Center for the first time and thought I'd share some pointers. I'll assume you are a registered Apple Developer and already understand how to create certificates and provisioning profiles.
The first thing to know is that to use Game Center you will need to create 2 App IDs for your game on developer.apple.com. One is a wildcard App ID and the other is an explicit App ID. On iTunes Connect when you create a new App you must choose a bundle ID (wildcard App ID) and then type a suffix that matches an exclusive App ID you have created.
For this example lets pretend my team is called Awesome, my certificate is for Brad on team awesome, and my provisioning profile is for team Awesome. Team Awesome's ID is ABCDE12345.
Creating App IDsRead Apple's Explanation here.
Go to developer.apple.com and create a new App ID. The description can be whatever you want. The prefix for your App ID is generated by Apple. I chose to use my team ID. Whatever team you are part of in your provisioning profile should match this prefix. You can ensure this by choosing Use Team ID when creating the App ID. This means my prefix will be ABCDE12345.
The bundle identifier is what determines if this App ID is wildcard or explicit. You'll need one of each to use Game Center. Lets create the wildcard App ID first; in this example it will be com.bradkeys.* Click submit and look at your list. Mine would look like ABCDE12345.com.bradkeys.* You'll see that your newly created App ID does not support Game Center and there's no way to enable it. That's ok!
Now to create a second App ID. Again choose a description, then use your team ID. Now for the bundle identifier use the same as your wildcard App ID but actually use a specific suffix. For this example I'll type com.bradkeys.myGame Click submit, check out your lovely list (mine looks like ABCDE12345.com.bradkeys.myGame) and bam you can see this one is good to go for Game Center (green lights).
Game Center Provisioning Profile You only need a provisioning profile from your explicit App ID. Go to provisioning in developer.apple.com, create a new one. Select your certificate, select your explicit App ID, and select the devices you want to test on. Finish and download the provisioning profile to your device(s) via Xcode.
Creating a Game Center App on iTunes Connect Go to iTunes Connect and choose to manage your apps. Create a new app and choose iOS. Your name and SKU can be whatever you like. Under Bundle ID, choose the wildcard App ID you just created. A suffix field now appears and here you finish the Bundle ID using the end of your explicit App ID. In this example I would select my com.bradkeys.* bundle and then type myGame inside the suffix field. The rest of the setup is straightforward. Once your new app and version are created, go to the Game Center link and create an achievement (also fairly straightforward to do).
Unity Player Settings In Unity go to your iOS Player settings (Edit -> Project Settings -> Player -> iOS) and in other settings make sure your bundle ID matches the bundle ID of your app in iTunes Connect. In my example it would be com.bradkeys.myGame (notice I didn't include my team ID).
Using Unity's Social API Although their documentation is pretty shotty right now, they do provide a complete example here that you can essentially copy and paste into your code and try. Do that.
Using Game Center in Sandbox Mode The last trick is to make sure you log out of Game Center on your mobile device. Open the Game Center app, on the main screen click your account and then choose to sign out. Close the Game Center app. Build and run your game from Unity.
Once your game is running on your device and it runs your script containing Unity's social API, it will attempt to log you into Game Center. Choose to sign in using an Apple Developer account (not sure if that's required, but that's what I did). If your credentials are wrong, it will say This game is not supported by Game Center. Which isn't true! Just restart your app and make sure you get your username and password right.
If you're not prompted to sign in with an account.. I did notice that on my iPad I had to sign in using the Game Center app itself and it said SandBox right there. After I signed in, I went back to my app and it worked correctly.
Once you are signed in a banner appears along the top alerting you that you have signed in and that you are in sandbox mode. If it doesn't say sandbox mode then you have done something wrong. But hopefully it does say it and from there and you can follow Unity's social API documentation to do whatever you fancy. Enjoy!