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.

caution

From Spring 2024, developers will have to clearly describe data use in the privacy manifest, showing how required reason APIs will be utilized in apps that are updated or uploaded to Apple App Store Connect.For more information, see Upcoming third-party SDK requirements.

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.1. Create an Application
  1. Register and authenticate your account on the Discord official website
  2. Go to the Developer Platform and click New Application

Image: Create Application

  1. Enter your application name and click Create
  2. On the General Information page, obtain the APPLICATION ID

Image: Obtain App ID

  1. Configure the Discord App ID in INTLConfig.ini
1.2. Apply for SDK Access
  1. Go to the Developer Platform
  2. Click Games - Social SDK, fill out the form, and submit

Image: Fill in form 1

Image: Fill in form 2

Important

Before the official launch of your game, notify the Discord team in advance to enable production permissions.

1.3. Configure OAuth2
  1. Click OAuth2 and turn on the PUBLIC CLIENT option

Image: PUBLIC CLIENT

  1. Configure Redirects:
    • Android/iOS: discord-{YOUR_APP_ID}:/authorize/callback
    • PC: http://127.0.0.1/callback
    • Web: https://common-web.intlgame.com/jssdk/discordlogincallback.html,
      https://test-common-web.intlgame.com/jssdk/discordlogincallback.html

Image: Configure Redirects

note

For multi-store channel packs:

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

note

For mobile platforms, if the app needs to redirect back to the game, DeepLink must be configured: add the redirect URL under General InformationDeep Link URL

Image: DeepLink configuration

1.4. Configure Rich Presence Assets
  1. Click Rich Presence
  2. Click Add Image(s) to upload image assets

Image: Upload assets

  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 should first find the bundled resource path in the Plugins/INTLSDK/Source/INTLCore/INTLCore.Build.cs file:

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":
[
"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}
  • Replace {INTL_DISCORD_APP_ID} with the Discord App ID for the game.
  1. Adds the Discord to the Info.plist file.

When exporting the Xcode project from Unity, confirm that INTLDiscordKit.projmods already includes the Discord callback scheme configuration.

note

The Player Network SDK has already written this configuration into INTLDiscordKit.projmods, so game teams usually only need to verify that the configuration exists and do not need to add it manually.

"CFBundleURLTypes" :
[
{
"CFBundleTypeRole":"Editor",
"CFBundleURLName":"Discord",
"CFBundleURLSchemes":["discord-{INTL_DISCORD_APP_ID}"]
}
]

Step 2:Add Discord Login

Discord does not require an application to be installed before logging in.If the app is installed, it will be opened for login; otherwise, login will be opened in the browser.

  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 AuthResult)
{
Debug.Log($"MethodID: {AuthResult.MethodId}");

string methodTag = "";
switch (AuthResult.MethodId)
{
case (int)INTLMethodID.INTL_AUTH_LOGIN:
methodTag = "Login";
break;
case (int)INTLMethodID.INTL_AUTH_BIND:
methodTag = "Bind";
break;
case (int)INTLMethodID.INTL_AUTH_AUTOLOGIN:
methodTag = "AutoLogin";
break;
case (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO:
methodTag = "QueryUserInfo";
break;
case (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT:
methodTag = "GetAuthResult";
break;
}
}
  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.