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
Log in to the Apple Developer Platform.
In the top navigation bar, click Account, and select Identifiers under Certificates, IDs & Profiles.
Click the blue add icon (+).
Select App IDs and click Continue.
Select App and click Continue.
Enter the Description and Bundle ID.
- Description: The name or description of the game app.
- Bundle ID: The unique identifier of the game app which is included in the app ID.
Under Capabilities, select Sign in with Apple and click Continue.
Click Register to create an App ID.
2. Set up App Store Connect
Sign in to App Store Connect.
Select App.
Click App (+) and choose Crean a new app.
Create an App Store Connect app based on the Bundle ID obtained in Step 1.
Select Feature > Game Center to enter the Game Center configuration page.
Enable the Game Center.
More information can be found at https://developer.apple.com/help/app-store-connect/
Leaderboard
Select Game Center on the left navigation bar and select Add leaderboards to create a new leaderboard or Add an achievement to add an achievement setting on the right.
Enter details as needed.
Click on the question mark (?) icon next to each field input box. ) icon next to each field input box and a detailed explanation will be given.
- Click Storage to save the configured leaderboard.
Users can add as many leaderboards as they want. Leaderboards support multiple languages, each language must be added separately. Achievement 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.