Skip to main content

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.

  1. Log in to the Apple Developer Platform.

  2. In the sidebar, click Certificates, IDs & Profiles.

  3. In the sidebar, click Identifiers and click the blue add icon (+).

    Image: Apple Identifiers

  4. Select App IDs and follow the guide to create an App ID.

  5. Save the Bundle ID for later use.

2. Set up iTunes Connect
  1. Log in to iTunes Connect.

  2. Based on the Bundle ID obtained in Step 1, create an iTunes Connect App.

    Image: GameCenter iTunes Connect 1

  3. Select Feature > Game Center and go to the Game Center configuration page.

  4. Enable the Game Center function.

  5. Set Leaderboard and Achievement.
    Achievements settings are similar to Leaderboard settings.

    Image: GameCenter iTunes Connect

Leaderboard
  1. On the Game Center configuration page, to the right of the Leaderboard, click the plus sign (+) to create a new Leaderboard.
  2. Enter detailed information as needed.
info

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.
  1. Click Save to save the configured leaderboard settings.

Image: GameCenter Leaderboard

info

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.

  1. Create an account for Player Network Console.
  2. Create a new project for your game, or join an existing one.
  3. Download the SDK.
  4. Integrate the SDK.
  5. Add Game Center as an authentication method for your project on Player Network Console.

Step 1: Configure the project for Game Center login

  1. 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.

  2. On the Signing & Capabilities page of the target project, add the Game Center capability by clicking the + Capability.

info

The System Library Dependencies GameKit.framework will be automatically added to the project dependencies in Xcode.

Image: Game Center 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.

    Image: Game Center login 1

  • 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.

    Image: Game Center login 2

  1. Add an observer to handle authentication callbacks.

    // 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";
    }
    }
  2. Call the AutoLogin method.

    INTLAPI.AutoLogin();
  3. Call the Login method to ask for user input if auto-login fails.

    INTLAPI.Login(INTLChannel.GameCenter);
  4. 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.