Skip to main content

iOS

This article guides you through setting up Discord as an identity provider, enabling your iOS game to access Player Network authentication services.

note

As authentication through the Discord App has been deprecated in the Discord SDK, using Discord App for authentication may encounter problems in the future. To ensure that Discord authentication remains reliable, we recommend using WebView instead for web authentication for Discord. For more details, see the configuration DISCORD_LOGIN_USING_WEB.

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.

As Discord has yet to publish their privacy manifest, such content is not available in the Player Network SDK privacy manifest, see iOS 17 Privacy Manifest for more information.

Prerequisites

1. Set up the Discord app on the Discord Developer Platform
note

For multi-store packages, a separate REDIRECT_URL_SCHEME is required. One app ID supports 10 Redirect URLs (about 4 multi-store packages). Apply for more app IDs if games require more than 4 multi-store packages. To use multiple app IDs, games need to configure multiple app IDs in INTLConfig.ini and register multiple Discord apps on the Player Network Console.

1. Create a Discord app

Before creating the Discord app, register an account on the Discord official website and complete the account authentication (by email) according to the prompts.

  1. Go to the Discord Developer Platform.
    On the first login, users might have to verify that they are not bots. You may complete it after the email verification.

  2. On the top right corner of the Applications page, click New Application.

    Image: Create an app

  3. In the app creation popup, enter the application name and click Create.

  4. On the General Information page, view the APPLICATION ID.
    Users must configure the app ID in the INTLConfig.ini file.

    Image: Get the ID

2. Configure the app

caution

The authentication feature on Player Network for Discord requires the identify scope from Discord. The social feature on Player Network requires the relationships.read and activities.write scope from Discord. The For more information, see OAuth2 Scopes.

  1. Go to the Discord Developer Platform.

  2. On the Applications page, click the app to configure.

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

  4. Under Redirects, fill in the below redirect URLs, which are used to receive callbacks after Discord web authorization. Click Add Another to add more empty fields if required:

    Image: Configure Redirect

    note

    To use the Discord app instead of Discord web for authorization on mobile devices, a redirect URL for the Discord app is required for callback after authorization. Redirect URL rules:

    • Use all lowercase.
    • The scheme should start 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 a universal link to open the game.
    2. Add the link to Redirect URL
    note

    For multi-store packages:

    A separate REDIRECT_URL_SCHEME is required to support multi-store packages. One app ID supports 10 Redirect URLs (about 4 multi-store packages). Apply for more app IDs if games require more than 4 multi-store packages. To use multiple app IDs, games need to configure multiple app IDs in INTLConfig.ini and register multiple Discord app on Player Network.

  5. Click Rich Presence in the left side navigation bar and go to the Rich Presence Art Assets page.

  6. Click Add Image(s) to configure the image resources of the app.

    Image: Configure resources

    info

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

  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 Discord as an authentication method for your project on Player Network Console.

Step 1: Configure the SDK for Discord login

Version Requirement

Discord SDK is only compatible with iOS SDK 11 and later.

info

Unreal Engine should first find the bundle 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. Load required permissions and plugins

XUPorter automatically adds dependency libraries and source code files when exporting Xcode projects to facilitate packaging.

Player Network SDK optimizes the original version of XUPorter which avoids the conflict between the XUPorter solution and the Player Network SDK solution.

  • The INTLSDKEditor namespace is added to avoid naming conflicts when other components also use XUPorter.
  • The search path to mods files is changed. In this way, Player Network SDK XUPorter only searches for mods files in the INTLSDK/ directory, rather than repeatedly adding the configurations of other components.
  • The lifecycle is added into UnityAppController.mm.

Player Network SDK XUPorter solution

INTL{Plugin}Kit.projmods is Player Network SDK Info.plist confiugration file. Player Network SDK reads the INTL{Plugin}Kit.projmods file in the INTLSDK/Editor/XUPorter/Mods directory and adds the imported bundle, framework, and other dependency packages in Xcode.

As each INTL{Plugin}Kit.projmods file corresponds to a plugin, games need to update each file according to game requirements for the plugin, and replace the {placeholder} text with values from the INTLConfig.ini configuration file.

For example, update INTLDiscordKit.projmods for required configurations.

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

iOS Usage Description

According to the requirements for iOS permissions, when requesting sensitive permissions, fill in usage description, when the system pops up and prompts the user for this information.

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

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

    When integrating, users can modify the contents according to their needs.

  2. In Assets/INTLSDK/Editor/XUPorter/Mods~/INTLADTrackingKit.projmods, the following permission has been upgraded:

    "NSUserTrackingUsageDescription"
    caution

    When integrating, users can modify the contents according to their needs, and confirm with the legal team if the contents are compliant. If there are no modifications, replace INTLSample with the game name.

2. Adapt to the Swift SDK

There will be mixed editing issue for iOS Swift and Objective-C if the module uses the Swift SDK. Take the following steps to create a bridge layer to align the class names of the two programming languages:

  1. Create a new file and choose the Swift File type.

    Image: Swift File type

  2. Specify the file name as needed and make sure that the extension is .swift. Then click on Create.

    Image: Create Swift file

  3. Click Create Bridging Header.

    note

    Make sure to select Create Bridging Header. Otherwise, Xcode will not create a bridge layer file.

    Images: Create bridge document

  4. Make sure two files are created in the Xcode project (one is the .swift file created in step 2, and the other is the automatically created project_name-Bridging-Header.h file).

    info

    The file content remains unchanged.

    Images: Confirm document

Not applicable.

3. Complete Player Network SDK configurations

  1. Open the project's INTLConfig.ini:

    [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 applying Discord App ID.
  • Replace {INTL_DISCORD_REDIRECT_URL} with the Redirect URL configured for you on the developer platform.
  • Replace {INTL_DISCORD_UNIVERSAL_LINK_IOS} with the Redirect universal link configurated on the developer platform.
  1. Add Discord to the Info.plist file.

When using Unity to export Xcode projects, configure the .projmods file.

note

Player Network SDK has already written these configurations into the INTLCoreKit.projmods file, so the game team simply need 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 app installation before login. If the app has already been installed, open the app to log in. Otherwise, the web login interface will open.

Discord login permission requires identify to be added. If the Discord sharing function is required, relationships.read,activities.write should be added.

  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.Discord, "identify", "");
    INTLAPI.Login(INTLChannel.Discord, "identify,relationships.read,activities.write", ""); //Friend functions
  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.