iOS
This article guides you through setting up Game Center as an identity provider, enabling your iOS game to access Player Network authentication services.
Prerequisites
1. Set up your game on the Apple Developer Center
1. Create an App ID
Register an Apple developer account and create an app on the Apple Developer Center.
Log in to the Apple Developer Platform.
In the sidebar, click Certificates, IDs & Profiles.
In the sidebar, click Identifiers and click the blue add icon (+).
Select App IDs and follow the guide to create an App ID.
Save the Bundle ID for later use.
2. Set up iTunes Connect
Log in to iTunes Connect.
Based on the Bundle ID obtained in Step 1, create an iTunes Connect App.
Select Feature > Game Center and go to the Game Center configuration page.
Enable the Game Center function.
Set Leaderboard and Achievement.
Achievements settings are similar to Leaderboard settings.
Leaderboard
- On the Game Center configuration page, to the right of the Leaderboard, click the plus sign (+) to create a new Leaderboard.
- Enter detailed information as needed.
Clicking the question mark (?) icon beside the input box for each field will give a detailed explanation.
- Sort Order: Sets whether the content in the leaderboard is sorted in ascending or descending order.
- Score Format Type: Sets the score type.
- Click Save to save the configured leaderboard settings.
Users can add multiple leaderboards as needed. Leaderboards support multiple languages, and each language must be added separately. Achievements settings are similar to Leaderboard settings.
- Create an account for Player Network Console.
- Create a new project for your game, or join an existing one.
- Download the SDK.
- Integrate the SDK.
- Add Game Center as an authentication method for your project on Player Network Console.
Step 1: Configure the project for Game Center login
On the Signing & Capabilities page of the target project, the Bundle Identifier must be an iOS app registered in App Store Connect.
Otherwise, when users log in to the Game Center, they will receive an error that says GameCenter is not supported.On the Signing & Capabilities page of the target project, add the Game Center capability by clicking the + Capability.
The System Library Dependencies GameKit.framework
will be automatically added to the project dependencies in Xcode.
Step 2: Add Game Center login
Game Center will continue to exist as a service in versions later than iOS 10, but an individual Game Center app will no longer appear on user devices. Users can go to Settings > Game Center to log in and continue using the related functions.
There are mainly two situations when users log in to Game Center within the game:
Already logged in via Settings > Game Center: Background login is performed, and a Welcome back, xxxx banner will be shown. The entire login process will not interrupt the game.
Not logged in via Settings > Game Center: A Game Center login box will pop up within the game. If users cancel the login three times, they will be unable to access the Game Center login box within the game and will need to go back to Settings > Game Center to log in to Game Center manually.
Add an observer to handle authentication callbacks.
- Unity
- Unreal Engine
// Add callbacks
public void AddAuthObserver()
{
INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
}
// Remove callbacks
public void RemoveAuthObserver()
{
INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
}
// Process the INTLAuthResult callback
public void OnAuthResultEvent(INTLAuthResult ret)
{
Debug.Log($"MethodID: {ret.MethodId}");
string methodTag = "";
if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
{
methodTag = "Login";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
{
methodTag = "Bind";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
{
methodTag = "AutoLogin";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
{
methodTag = "QueryUserInfo";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
{
methodTag = "GetAuthResult";
}
}C++ Event Handling (above v1.15)
//configure callback
FINTLAuthEvent authEvent;
authEvent.AddUObject(this, &OnAuthResult_Implementation);
UINTLSDKAPI::SetAuthResultObserver(authEvent);
// Remove callbacks
UINTLSDKAPI::GetAuthResultObserver().Clear();void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Unreal Event Handling
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Call the
AutoLogin
method.- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
Call the
Login
method to ask for user input if auto-login fails.- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.GameCenter);
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelGameCenter);
Sync client authentication state with the game's backend and wait for the final authentication result.
Step 3: Test the login function
Search for the keyword "AuthResult" in the Player Network SDK logs to verify if the correct channel name and OpenID are returned. If they are, it indicates a successful configuration and the login function has been added successfully.