# Apple Game Center

{% hint style="info" %}
Apple Game Center platform needs to be enabled and configured in the Web Console before it can be used in your game. This also requires you to have a developer account with Apple.
{% endhint %}

#### Configuration

{% tabs %}
{% tab title="Unity" %}
First start by installing the [GameKit ](https://developer.apple.com/documentation/gamekit)Unity Plugin found in the [Apple Unity Repository](https://github.com/apple/unityplugins).

Then in the Unity Editor menu, go to **Edit** > **Project Settings…**, then select **Services** > **Authentication** from the navigation menu.

Set **ID Providers** to **Apple Game Center**, then select **Add**.

Enter the **Bundle ID** from the Apple developer console in the **Bundle ID** text field, then select **Save**. The Bundle ID should look like this: "**com.lootlocker.hector**".
{% endtab %}

{% tab title="Unreal" %}
**Please see Unreal's** [**guide**](https://docs.unrealengine.com/4.27/en-US/SharingAndReleasing/Mobile/iOS/Setup/) **on how to configure your project to gain access to the necessary calls to use Apple Game Center Authentication.**
{% endtab %}
{% endtabs %}

{% hint style="danger" %}
The timestamp input will only be valid for 30 minutes for security reasons.
{% endhint %}

#### Start Session

{% hint style="info" %}
We do store the Refresh Token for the next time the player starts your game. This Token can be used to Refresh a Session which uses a simpler flow.
{% endhint %}

{% tabs %}
{% tab title="Unity" %}

```csharp
string bundleId;
string signature;
string playerId;
string salt;
string publicKeyUrl;
string timestamp;

LootLockerSDKManager.StartAppleGameCenterSession(bundleId, playerId, publicKeyUrl, signature, salt, timestamp, (response) => 
{

    if (!response.success)
    {
        Debug.Log("error starting LootLocker session");

        return;
     }

     Debug.Log("successfully started LootLocker session");

});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-60161aaa84da3630dc708f387177efd5032a01e6%2Fimage.png?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/ftj1rgjz/">Blueprint example of starting an apple game center session</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}

```bash
curl -X POST "https://api.lootlocker.io/game/session/apple/game-center" \
  -H "LL-Version: 2021-03-01" \
  -H "Content-Type: application/json" \
  -d "{\"game_key\": \"your_game_key\", \"bundle_id\": \"apple.bundle.id\", \"player_id\": \"T:_e66eaa73fcd186b1b3e9dc22e19398e4\", \"public_key_url\": \"https://static.gc.apple.com/public-key/gc-prod-9.cer\", \"signature\": \"x+D8j5ulh6/m1O6yW5mKuaX ... G3vEwHLxsYGLjSVn53XVshIFL528=\", \"salt\": \"UIzs/Q==\", \"timestamp\": 1680781286451, \"game_version\": \"1.0.0.0\" }"
```

Example response:

```json
{
  "session_token": "eb13a7bf17efg36cb8481a8ds18809c7e85686e6",
  "player_id": 9358,
  "public_uid": "J72YP6MS",
  "player_name": null,
  "player_created_at": "2023-02-21T15:33:25+00:00",
  "check_grant_notifications": false,
  "check_deactivation_notifications": false,
  "seen_before": false,
  "refresh_token": "eyJh............................."
}
```

{% endtab %}
{% endtabs %}

#### Refresh Session

Refreshing a Session can be done in order to start the session without going through the entire StartAppleGameCenterSession() flow, if your session token is still valid.

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.RefreshAppleGameCenterSession((response) => 
{     
    if (!response.success)
    {
        if (response.statusCode == 401) {
            // Refresh token has expired, use StartAppleGameCenterSession
        }
        else {
            Debug.Log("error starting LootLocker session");
        }

        return;
    }

    Debug.Log("session started successfully");   
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-9266d4764170df6a68bc67b87667be3b9a4985fc%2Fimage.png?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/1bgf0-zk/">Blueprint example of refreshing an apple game center session</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}

```bash
curl -X POST "https://api.lootlocker.io/game/session/apple/game-center" \
  -H "LL-Version: 2021-03-01" \
  -H "Content-Type: application/json" \
  -d "{\"game_key\": \"your_game_key\", \"refresh_token\": \"748b....\", \"game_version\": \"1.0.0.0\" }"
```

Example response:

```json
{
  "session_token": "eb13a7bf17efg36cb8481a8ds18809c7e85686e6",
  "player_id": 9358,
  "public_uid": "J72YP6MS",
  "player_name": null,
  "player_created_at": "2023-02-21T15:33:25+00:00",
  "check_grant_notifications": false,
  "check_deactivation_notifications": false,
  "seen_before": false,
  "refresh_token": "eyJh............................."
}
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
Congratulations - you have now started using LootLocker in your game with Apple Game Center! Next up we suggest you look at our [feature set,](https://docs.lootlocker.com/the-basics/what-is-lootlocker#overview) and decide which ones you want to use in your game.
{% endhint %}
