Skip to main content

iOS

The purpose of this article is to describe how to set up Discord authentication so that your game can be logged in through the Discord channel using the Player Network login authentication service.

note

As the Discord SDK has stopped maintaining a license method for pulling up Discord Apps, there may be subsequent impacts on Discord App licensing.To ensure that Discord authorization is stable and available, it is recommended to use WebView for web authorization, see Configuring DISCORD_LOGIN_USING_WEB for details.

caution

从 2024 年春季开始,对于需更新或上传至 Apple App Store Connect 的应用,开发者需明确 注明使用原因,以展示该应用如何使用 required reason API(需提交使用原因的 API)。更多信息,请参见 即将发布的第三方 SDK 要求

Since Discord's privacy manifest has not yet been released, the corresponding content is not included in the Player Network SDK privacy manifest. For details, see iOS 17 Privacy Manifest.

Prerequisites

1. Configuring the application on the Discord Developer Platform
1. Create Discord Application

Before creating a Discord application, register an account on the official Discord website and follow the prompts to complete account authentication (via email).

  1. Enter Discord Developer Platform.
    When logging in for the first time, users may need to verify that they are not a robot.You can do this after email verification.
  2. In the upper right corner of the Applications page, click New Application.

Image: Create Application

  1. In the application creation window that pops up, enter the application name and click Create.
  2. On the General Information page, view the APPLICATION ID.
    The user must configure the App ID in the INTLConfig.ini file.

Image: Obtain ID

2. Configure Application
  1. Go to Discord Developer Platform.

  2. Click the application to configure on the Applications page.

  3. Click OAuth2 in the left navigation bar and go to OAuth2 > General.

  4. Configure the following redirect URLs under Redirects to receive callbacks after authorization on the Discord web page by clicking Add Another to add the cell:

    Image: Configure Redirect

note

On mobile, if you want to authorize using the Discord app instead of the Discord webpage, you will also need to fill in a redirect URL for the Discord app post-authorization callback. Redirect URL Rules:

  • Use all lowercase.
  • Programs should begin with "intl".
  • The URL should include the host and path.

Example: intlmoba://auth/callback

note

For INTLConfig.ini's DISCORD_UNIVERSAL_LINK_IOS.

  1. Configure open a generic link to the game.
  2. Add link to Redirect URL
note

A separate REDIRECT_URL_SCHEME is required for the multi-store channel package:.

Support for multi-store channel packages requires a separate REDIRECT_URL_SCHEME.An App ID supports 10 redirect URLs (about 4 multi-store channel packs).If the game requires more than 4 multi-store channel packs, please request more App IDs.To use multiple application IDs, the game requires Configure multiple application IDs in INTLConfig.ini and Register multiple Discord applications on Player Network.

  1. Click Rich Presence in the left navigation bar and enter Rich Presence Art Assets page.

  2. Click Add Image(s) to configure the application's image resources.

    Image: Configure resources

info

All image resources used in the application must be configured on this page, including the cover photo for friend invitations.

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

Step 1:Configuring the SDK for Discord Login

Version Requirement

The Discord SDK is only compatible with iOS 12.0 and later.

info

Unreal Engine 应首先在 Plugins/INTLSDK/Source/INTLCore/INTLCore.Build.cs 文件中找到捆绑资源路径:

AdditionalBundleResources.Add(new BundleResource(Path.Combine(ModuleDirectory, "Libs/iOS/INTLCore/INTLSDK.bundle"), bShouldLog: false));

1. Loading required permissions and plug-ins

Open the INTLDiscordKit.projmods file and replace {INTL_DISCORD_APP_ID} with the App ID of the game.

"Info.plist":{
"LSApplicationQueriesSchemes":
[
"com.hammerandchisel.discord"
],
"NSAppTransportSecurity":
{
"NSAllowsArbitraryLoads". true
},
"CFBundleURLTypes" :
[
{
"CFBundleTypeRole": "Editor",
"CFBundleURLName": "Discord",
"CFBundleURLSchemes": ["discord-{INTL_DISCORD_APP_ID}"]
}
]
}

iOS Instructions for Use

According to iOS permission requirements, when applying for sensitive permissions, fill in Usage Instructions, and the system will pop up to prompt the user to fill in this information.

  1. In Assets/INTLSDK/Editor/XUPorter/Mods~/INTLCoreKit.projmods, the following permissions have been escalated:

    "NSPhotoLibraryUsageDescription"
    "NSCameraUsageDescription"
    "NSLocationWhenInUseUsageDescription"
    "NSPhotoLibraryAddUsageDescription"
    "NSMicrophoneUsageDescription"

    At the time of access, the user can modify the content as needed.

  2. In Assets/INTLSDK/Editor/XUPorter/Mods~/INTLADTrackingKit.projmods, the following permissions have been escalated:

    "NSUserTrackingUsageDescription"
caution

Upon access, users can modify content as needed** and confirm content compliance with the legal team**.If there are no changes, replace INTLSample with the game name.

2. Swift SDK Adapter

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 and choose 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 Header

  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 need to modify the file contents.

Image: Confirm Documents

Not applicable.

3. Complete Player Network SDK configuration

  1. Open your project's INTLConfig.ini file:
[Discord channel configuration]
DISCORD_APP_ID = {INTL_DISCORD_APP_ID}
DISCORD_REDIRECT_URL = {INTL_DISCORD_REDIRECT_URL}
DISCORD_UNIVERSAL_LINK_IOS = {INTL_DISCORD_UNIVERSAL_LINK_IOS}
  • Replace {INTL_DISCORD_APP_ID} with the Discord App ID for the game.
  • Replace {INTL_DISCORD_REDIRECT_URL} with the Redirect URL configured on the platform.
  • Replace {INTL_DISCORD_UNIVERSAL_LINK_IOS} with the Redirect generic link configured on the developer platform.
  1. Adds the Discord to the Info.plist file.

When exporting an Xcode project using Unity, configure the .projmods file.

note

The Player Network SDK already writes these configurations to the INTLCoreKit.projmods file, so the game team only needs to check the configurations.

{
"group": "INTL",
"Info.plist":{
"CFBundleURLTypes" :
[
{
"CFBundleTypeRole":"Editor",
"CFBundleURLName":"Discord",
"CFBundleURLSchemes":["{INTL_DISCORD_REDIRECT_SCHEME}"]
}
]
},
}

Replace {INTL_DISCORD_REDIRECT_SCHEME} with the scheme configured in the redirect URL.

note

For example, if the Redirect URL configured on the Discord Developer Platform is intlsample://auth/callback

{INTL_DISCORD_REDIRECT_SCHEME} = intlsample

Step 2:Add Discord Login

Discord does not require an application to be installed before logging in.If the app is installed, it will open the app login, otherwise it will open the web page login.

Discord login permission needs to add identify.If you need to integrate Discord sharing, add relationships.read,activities.write as well.

  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 to log in automatically.
INTLAPI.AutoLogin();
  1. If automatic login fails, call the Login interface to let the player log in manually.
INTLAPI.Login(INTLChannel.Discord, "identify", "");
INTLAPI.Login(INTLChannel.Discord, "identify,relationships.read,activities.write", ""); //Friend functions
  1. Synchronize client authentication status with the game backend and wait for the final verification result.

Step 3: Acceptance testing for login functionality

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

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