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
  1. Log in to the Apple Developer Platform.

  2. In the top navigation bar, click Account, and select Identifiers under Certificates, IDs & Profiles.

    Image:Apple Account

  3. Click the blue add icon (+).

    Image: Apple Identifiers

  4. Select App IDs and click Continue.

    Image: Apple App ID

  5. Select App and click Continue.

    Image:Apple App ID

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

    Image: Apple bundle description

  7. Under Capabilities, select Sign in with Apple and click Continue.

  8. Click Register to create an App ID.

2. Set up App Store Connect
  1. Sign in to App Store Connect.

  2. Select App.

    Image: GameCenter ChooseApp

  3. Click App (+) and choose Crean a new app.

    Image: GameCenter AddApp

  4. Create an App Store Connect app based on the Bundle ID obtained in Step 1.

    Image: GameCenter iTunes Connect 1

  5. Select Feature > Game Center to enter the Game Center configuration page.

  6. Enable the Game Center.

    More information can be found at https://developer.apple.com/help/app-store-connect/

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

    Image: GameCenter iTunes Connect

  2. Enter details as needed.

info

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.

  1. Click Storage to save the configured leaderboard.

Image: GameCenter Leaderboard

info

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.

  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.