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.
2. Get the app information
Log in to WeChat Open Platform.
At the top navigation bar, click Admin Center.
In the Mobile App tab, click View in the Actions column of the corresponding application.
On the app details page, check the AppID and AppSecret.
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.
- Create an account for Player Network Console.
- Create a new project for your game, or join an existing one.
- Download the SDK.
- Integrate the SDK.
- Add WeChat as an authentication method for your project on Player Network Console.
Step 1: Configure the SDK for WeChat login
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 theGAME_ID
andSDK_KEY
assigned by Player Network Console. - Set
LOG_LEVEL = 1
,LOG_CONSOLE_OUTPUT_ENABLE = 1
,LOG_FILE_OUTPUT_ENABLE = 1
,LOG_ENCRYPT_ENABLE = 0
, andLOG_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 theUNIVERSAL_LINK
set on the WeChat Open Platform.
- Set the SDK backend environment to
Add WeChat to the
Info.plist
file.- Unity
- Unreal Engine
noteCheck 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}"]
}
],
}
}- Player Network SDK 1.18 or later
- Before Player Network SDK 1.18
Open and modify the file that corresponds to your SDK version:
- For V1.24 or later:
INTLSDK/Source/INTLWeChat/Libs/iOS/INTLWeChat_UPL.xml
- For V1.18 to V1.23:
INTLSDK/Source/INTLConfig/Configs/iOS/Plist/INTLWeChat.plist
<key>CFBundleURLSchemes</key>
<array>
<string>{INTL_WECHAT_APP_ID}</string>
</array>Go to Unreal Engine > Settings > Project Settings > Platforms > iOS > Extra Plist Data to modify the configuration,and add SDK to the PLIST file.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>{INTL_WECHAT_APP_ID}</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wechat</string>
<string>weixin</string>
<string>weixinULAPI</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>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):
Permissions | Description |
---|---|
snsapi_userinfo | Obtains user information (Player Network SDK's default permission) |
snsapi_friend | Gets friend list |
snsapi_message | Sends message |
Add an observer to handle authentication callbacks.
- Unity
- Unreal Engine
// 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";
}
}C++ Event Handling (above v1.15)
//configure callback
FINTLAuthEvent authEvent;
authEvent.AddUObject(this, &OnAuthResult_Implementation);
UINTLSDKAPI::SetAuthResultObserver(authEvent);
// Remove callbacks
UINTLSDKAPI::GetAuthResultObserver().Clear();void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Unreal Event Handling
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Call the
AutoLogin
method.- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
Call the
Login
method to ask for user input if auto-login fails.- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.WeChat, "", "");
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelWeChat, "", "");
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.