Android
本文旨在介绍如何设置 Supercell 身份验证,让您的游戏可以使用 Player Network 登录鉴权服务通过 Supercell 渠道登录。
前提条件
1. 获取应用信息
Get required app information from the Supercell team.
- 获取 Player Network 控制台登录账号。
- 为游戏创建新项目,或加入已有项目。
- 下载 SDK。
- 接入 SDK。
- 在 Player Network 控制台添加 Supercell 为业务的登录鉴权方式。
步骤1:Configure the SDK
As Supercell SDK is only compatible with minSdkVersion >= 21, problems may occur while running on devices with Android 5.0 or lower versions. It is required to set minSdkVersion >= 21 for your game.
For more information, see Integrate into Android.
In the
AndroidManifest
file, add required permissions. Supercell 需要网络访问权限以获取网络信息状态,同时需要写入 SD 卡的权限。警告WRITE_EXTERNAL_STORAGE
为敏感权限。<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />Open the project's INTLConfig.ini:
[Supercell]
SUPERCELL_GAME_ID = {INTL_SUPERCELL_GAME_ID}
SUPERCELL_GAME_ENVIRONMENT = {INTL_SUPERCELL_GAME_ENVIRONMENT}
SUPERCELL_IS_PRODUCTION = {IS_USING_PRODUCTION}- Replace
{INTL_SUPERCELL_GAME_ID}
with the GAME_ID assigned by Player Network Console. - Replace
{INTL_SUPERCELL_GAME_ENVIRONMENT}
with the environment you are using, such as dev or prod. - Set
{IS_USING_PRODUCTION}
, 1 indicates a production environment, and 0 indicates any other environment.
- Replace
步骤2:Add Supercell login
注册登录相关回调。
- 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);
}调用
AutoLogin
接口自动登录。- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
在自动登录失败时调用
Login
接口使玩家手动登录。- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.Supercell);
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelSupercell);
与游戏后台同步客户端身份验证状态,等待最终验证结果。
步骤3:验收登录功能
在 Player Network SDK 日志中搜索关键字 "AuthResult" 确认渠道名称和 OpenID 是否正确返回。如果正确,则表明集成配置成功,登录功能已成功添加。
如果接入过程中遇到问题,请参见 常见问题。