Skip to main content

iOS

This document aims to introduce how to set up Apple authentication so that your game can log in through the Apple channel using Player Network login authentication services.

Prerequisites

1. Configure iOS app on Apple Developer
1. Create App ID

Create a client_id as the request source sent to Apple. The client_id for the iOS app is App ID (Bundle ID).

info

If you are using an existing App ID, simply click the corresponding App ID on the Identifiers page and open Sign in with Apple under Edit your App ID Configuration.

  1. Log in to Apple Developer, click Account in the top navigation bar, and select Certificates, IDs & Profiles under Identifiers.

    Image: Apple Account

  2. Click the blue add icon ( + ).

    Image: Apple Identifiers

  3. Select App IDs and then click Continue.

    Image: Apple App ID

  4. Select App and then click Continue.

    Image: Apple App ID

  5. Enter Description and Bundle ID.

    • Description: The name or description of the game app.
    • Bundle ID: The unique identifier of the game app included in the App ID.

    Image: Apple bundle description

  6. Open Sign in with Apple under Capabilities.

  7. Click Continue > Register to create App ID.

2. Create a key for accessing services

Create the key for calculating client_secret and the corresponding Key ID.

  1. In the Certificates, Identifiers & Profiles sidebar, click Keys.

  2. Click the blue add icon ( + ).

    Image: Apple Key

  3. Under Key Name, enter a unique name for the key.

  4. Select the checkbox next to Sign in with Apple and then click Configure.

    Image: Apple Key Name

  5. Under Primary App ID, choose the App ID created in the previous step, then click Save.

    Image: Apple Save Primary Key

  6. Click Continue.

  7. Click Register to generate the key and note down the Key ID.

  8. Click Download to download the key file ( download only once, do not lose it ). The file is saved as a text file with the .p8 suffix.

3. Create preset development profile
  1. Click Profiles in the Certificates, Identifiers & Profiles sidebar.
    Profiles are development profiles.

  2. Click the blue add icon ( + ).

    Image: Apple Profiles

  3. Under Development, choose the type of preset profile you want to create and click Continue.

  4. Select the App ID to use for development and click Continue.

  5. Choose one or more development certificates and click Continue.

  6. Select one or more devices and click Continue.

  7. Enter profile name and click Generate.

  8. Click Download.

4. Obtain Team ID
  1. Log in to Apple Developer.

  2. In the top navigation bar of the developer account, click Account, scroll to find Membership details to view Team ID.

    Image: Apple Team ID

For more information about Apple Developer configuration, refer to What the Heck is Sign In with Apple?.

  1. Obtain your Player Network Console login account.
  2. Create a new project for your game, or join an existing project.
  3. Download SDK.
  4. Integrate SDK.
  5. Add Apple as a login authentication method in Player Network Console.

Step 1: Configure SDK for Apple login

Version Requirement

iOS 12.0 and above

1. Swift SDK Bridging

If the module uses Swift version SDK, this involves the integration of iOS' Swift and Objective-C. Xcode requires a bridging layer to align the class names, etc., of the two languages for compatibility. Follow these steps.

  1. Create a new file, select Swift File type.

    Image: Swift File Type

  2. Name it according to your needs and ensure the file suffix is .swift, then click Create.

    Image: Create Swift File

  3. Click Create Bridging Header.

note

Make sure to select Create Bridging Header.Otherwise, Xcode will not create the bridging file.

Image: Create Bridging Document

  1. Ensure two files are created in the Xcode project (one is the .swift file from step two, and the other is the automatically created project_name-Bridging-Header.h file).
info

No changes needed to file content.

Image: Confirm Document

Not applicable.

2. Add functionality in Xcode

Image: Xcode Setting 1

3. Add AuthenticationServices.framework in Xcode BuildPhases and set its Status to optional.

Image: Xcode Setting 2

Other Unity configurations

  1. Check the configurations written in INTLCoreKit.projmods.

    {
    "group": "INTL",
    "libs": [],
    "frameworks": ["AuthenticationServices.framework:weak"],
    "files": [],
    "folders": [],
    "excludes": [],
    "headerpaths":[],
    "build_settings": {},
    "system_capabilities": {},
    "Info.plist":{}
    }
  2. Add entitlement file.
    For adding entitlement file to Unity, refer to the solution on Unity Forum.

    Sample: INTLDevDemo.entitlements

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>com.apple.developer.applesignin</key>
    <array>
    <string>Default</string>
    </array>
    </dict>
    </plist>

Step 2: Add Apple login

caution
  1. Apple login cannot be tested through re-sign packages; it is recommended to use TestFlight or Dev packaging.
  2. Apple login does not provide PictureUrl (user avatar URL).For more information, see INTLAuthResult for Unity engine or FINTLAuthResult for Unreal Engine.

Pass email and fullName as login permission parameters in the Login interface:

  • On the first login screen, options include editing the username and hiding the email (Fig 2).The callback retrieves email and fullName.
    • If players choose to hide email, a random email address is received.
    • If players choose to share email, the real email address of the user is obtained.
  • Subsequent logins will not obtain email and fullName, and the login interface (Fig 2) does not have options to edit the username and hide the email.
  • If a player logs in again after stopping app with Apple ID, the options shown in Fig 1 will appear.
info

Players can choose Settings > [Your Username] > Password & Security > Use Apple ID > [App Name] > Stop Using Apple ID to prevent the app from continuing to use Apple ID to login.

When the login permission parameter of the Login interface is an empty string, the login interface doesn't have options to edit the username and hide the email (Fig 2).In the callback, email and fullName are empty.

Fig 1:
Image: apple_login_permission

Fig 2:
Image: apple_login_permission2

  1. Register login-related 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";
}
}
  1. Call the AutoLogin interface for automatic login.
INTLAPI.AutoLogin();
  1. If automatic login fails, call the Login interface for players to manually log in.
INTLAPI.Login(INTLChannel.Apple); 
  1. Synchronize client authentication status with the game backend, waiting for the final authentication results.

[Optional] Set email permissions

note

Apple requires player authorization to obtain the player's email. If the player refuses authorization, the email cannot be obtained. Refer to Login interface passing email and fullName.

To obtain the player's email during Apple login, the corresponding permission must be set first. Once enabled, it returns email in AuthResult's ChannelInfo.

  • For compliance considerations, a mask can be applied to the returned email from specific sources. Contact the Player Network assistant to enable this if needed.
  • In the backend transaction logs, report the hash of base64(sha256(email)). Contact the Player Network assistant to enable this if needed.
  • Can be used to verify whether the player's information or binding list includes email information. Contact the Player Network assistant to enable this if needed.
  • Can be used for iOS Firebase's Private Set Membership (PSM) feature. See Firebase iOS Project Configuration.
  1. When calling the Login interface, add the email permission in the permissions parameter.

  2. Enable the email return feature in the Player Network Console by setting return_email to YES. For details, see Third-Party Channel Configuration.

Step 3: Verifying Login Functionality

Search for the keyword "AuthResult" in the Player Network SDK logs to confirm whether the channel name and OpenID are correctly returned.If correct, it indicates successful integration configuration and the login functionality has been successfully added.

If you encounter problems during the integration process, please refer to Frequently Asked Questions.