Skip to main content

iOS

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

Prerequisites

1. Set up the WeChat app on the WeChat Open Platform
1. Create a WeChat app

Register an account on the WeChat Open Platform and create a mobile app in the Admin Center according to the prompts.

Image: Open Platform of WeChat (1)

2. Get the app information
  1. Log in to WeChat Open Platform.

  2. At the top navigation bar, click Admin Center.

  3. In the Mobile App tab, click View in the Actions column of the corresponding application.

    Image: Open Platform of WeChat (2)

  4. On the app details page, check the AppID and AppSecret.

    Image: Open Platform of WeChat (3)

3. Apply for permissions for your project to obtain AppName

When configuring for a single WeChat channel, AppName is optional. However, when adding multiple WeChat channels, AppName is required and permission has to be obtained from the WeChat management system.

Applying for permissions on WeChat requires internal Tencent access, reach out to the Player Network representative for further assistance.

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

Step 1: Configure the SDK for WeChat login

  1. Open the INTLConfig.ini file.

    INTLConfig.ini
    [INTL environment]
    # WARNING: You should change this URL to the production environment when you release your game.
    INTL_URL = https://test.intlgame.com
    GAME_ID = {INTL_GAME_ID}
    SDK_KEY = {INTL_SDK_KEY}
    [INTL Log]
    LOG_LEVEL = 1
    LOG_CONSOLE_OUTPUT_ENABLE = 1
    LOG_FILE_OUTPUT_ENABLE = 1
    LOG_ENCRYPT_ENABLE = 0
    LOG_COMPRESS_ENABLE = 0
    [WeChat Channel]
    WECHAT_APP_ID = {INTL_WECHAT_APP_ID}
    WECHAT_UNIVERSAL_LINK_IOS = {WECHAT_UNIVERSAL_LINK_IOS}
    • Set the SDK backend environment to INTL_URL = https://test.intlgame.com.
    • Replace {INTL_GAME_ID} and {INTL_SDK_KEY} with the GAME_ID and SDK_KEY assigned by Player Network Console.
    • Set LOG_LEVEL = 1, LOG_CONSOLE_OUTPUT_ENABLE = 1, LOG_FILE_OUTPUT_ENABLE = 1, LOG_ENCRYPT_ENABLE = 0, and LOG_COMPRESS_ENABLE = 0 to output console logs and log files without encrypting or compressing the output.
    • Replace {INTL_WECHAT_APP_ID} with the AppID assigned by WeChat.
    • Replace {WECHAT_UNIVERSAL_LINK_IOS} with the UNIVERSAL_LINK set on the WeChat Open Platform.
  2. Add WeChat to the Info.plist file.

    note

    Check the predefined values in INTLCoreKit.projmods and replace {INTL_WECHAT_APP_ID} with the WeChat AppID before exporting the Xcode project from Unity.

    {
    "group": "INTL",
    "libs": [

    ],
    "frameworks": [

    ],
    "files": [
    ],
    "folders": [],
    "excludes": [
    "^.*.meta$",
    "^.*.mdown$",
    "^.*.pdf$"
    ],
    "headerpaths":[],
    "build_settings":
    {
    "OTHER_LDFLAGS": ["-ObjC"],
    "ENABLE_BITCODE": "FALSE",
    },
    "system_capabilities": {
    },
    "Info.plist":{
    "LSApplicationQueriesSchemes":
    [
    "weixin",
    "weixinULAPI"
    ],
    "NSAppTransportSecurity":
    {
    "NSAllowsArbitraryLoads":true
    },
    "CFBundleURLTypes" :
    [
    {
    "CFBundleTypeRole":"Editor",
    "CFBundleURLName":"wechat",
    "CFBundleURLSchemes":["{INTL_WECHAT_APP_ID}"]
    }
    ],
    }
    }

    Replace {INTL_WECHAT_APP_ID} as the WeChat App ID applied in the game.

Step 2: Add WeChat login

Permissions are configured when INTLAPI.Login is called. The list of known permissions for WeChat iOS is as follows (the official document does not have a clear permission description):

PermissionsDescription
snsapi_userinfoObtains user information (Player Network SDK's default permission)
snsapi_friendGets friend list
snsapi_messageSends message
  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.WeChat, "", "");
  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.