iOS
本文旨在介绍如何设置 Garena 身份验证,让您的游戏可以使用 Player Network 登录鉴权服务通过 Garena 渠道登录。
前提条件
1. 设置 Garena 应用
联系 Garena 团队激活应用程序并获取应用程序 ID 和其他相关信息。
要使用 Garena 的平台账号绑定,请请求 Garena 启用 APP_PLATFORM_BIND
。
步骤1:为 Garena 登录配置 SDK
打开 INTLConfig.ini 文件。
INTLConfig.ini[INTL environment]
# WARNING: You should change this URL to the production environment when you release your game.
INTL_URL = https://intlsdk-new-test.iegg.garena.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
[Garena Channel Configurations]
GARENA_APP_SDK_ASSIGN_ID = {INTL_GARENA_APP_SDK_ASSIGN_ID}
GARENA_APP_SDK_KEY = {INTL_APP_KEY}- 将 Player Network SDK 鉴权域名设置为
INTL_URL = https://intlsdk-new-test.iegg.garena.com
,可联系 Garena 团队了解详情并获取正式环境 URL。 - 将
{INTL_GAME_ID}
和{INTL_SDK_KEY}
替换为 Player Network 控制台 分配的GAME_ID
和SDK_KEY
的值。 - 设置
LOG_LEVEL = 1
、LOG_CONSOLE_OUTPUT_ENABLE = 1
、LOG_FILE_OUTPUT_ENABLE = 1
、LOG_ENCRYPT_ENABLE = 0
和LOG_COMPRESS_ENABLE = 0
,以便在不加密或压缩输出的情况下输出控制台日志和日志文件。 - 将
{INTL_GARENA_APP_SDK_ASSIGN_ID}
替换为已注册的 Garena App ID。 - 将
{INTL_APP_KEY}
替换为已注册的 Garena App Key。
- 将 Player Network SDK 鉴权域名设置为
将 Garena 添加到
Info.plist
文件中。注意Player Network SDK V1.15 及更高版本需要添加
AppTrackingTransparency.framework
。早于 Player Network SDK V1.15 的版本则不需要添加。Player Network SDK V1.22 中更新了 Garena SDK 的版本,接入 V1.22 还需要在
Info.plist
中添加FacebookClientToken
, 并将{INTL_FACEBOOK_CLIENT_TOKEN}
替换为相应的值。同时,Garena SDK 还引入了 DataDome SDK,需要在Info.plist
中添加DataDomeKey
以及DataDomeProxyEnabled
。Player Network SDK V1.24 中开始支持 iOS Garena
Google
子渠道登录,接入 V1.24 还需要在Info.plist
中添加GIDClientID
和基于反转客户端 ID 的自定义 URL,并将{INTL_GOOGLE_CLIENT_KEY_IOS}
和{INTL_GOOGLE_REVERSED_CLIENT_ID}
替换为相应的值。有关
DateDomeKey
和DataDomeProxyEnabled
的配置请参见 Garena: Upgrade to 4.0.21。- Unity
- Unreal Engine
注意从 Unity 导出 Xcode 项目之前,请检查
INTLGarenaKit.projmods
中的预定义值,并将{INTL_FACEBOOK_APP_ID}
、{INTL_FACEBOOK_CLIENT_TOKEN}
、{INTL_FACEBOOK_APP_NAME}
、{INTL_GARENA_APP_SDK_ASSIGN_ID}
、{INTL_GOOGLE_CLIENT_KEY_IOS}
和{INTL_GOOGLE_REVERSED_CLIENT_ID}
替换为应用程序的相应值。INTLGarenaKit.projmods{
"group": "INTL",
"libs": [
"libz.tbd",
"libc++.tbd"
],
"frameworks": [
"Accelerate.framework",
"Accounts.framework",
"AdSupport.framework",
"AuthenticationServices.framework:weak",
"AVFoundation.framework",
"CoreGraphics.framework",
"CoreMedia.framework",
"CoreServices.framework",
"CoreTelephony.framework",
"Foundation.framework",
"JavaScriptCore.framework",
"LocalAuthentication.framework",
"MapKit.framework",
"MobileCoreServices.framework",
"Photos.framework",
"ReplayKit.framework",
"SafariServices.framework",
"Security.framework",
"Social.framework",
"StoreKit.framework",
"SystemConfiguration.framework",
"UIKit.framework",
"WebKit.framework",
"AppTrackingTransparency.framework:optional"
],
"embed_binaries": [
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/DataDomeSDK.framework"
],
"files": [
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/DataDomeSDK.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/AppAuth.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/FBAEMKit.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/FBSDKCoreKit_Basics.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/FBSDKCoreKit.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/FBSDKGamingServicesKit.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/FBSDKLoginKit.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/FBSDKShareKit.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKDebugSystem.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKFriends.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKLoginFacebook.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKLoginGarena.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKLoginGoogle.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKLoginSwift.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKNotification.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKParentalControl.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKPayment.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKSecurityVerifier.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKShareFacebook.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKShareGarena.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKShareLine.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKShareSwift.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GarenaMSDKUtilities.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GoogleSignIn.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GTMAppAuth.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/GTMSessionFetcher.framework",
"../../../Plugins/iOS/INTLSDK/INTLGarena/ThirdSDK/Sentry.framework"
],
"folders": ["../../../Plugins/iOS/INTLSDK"],
"excludes": [
"^.*.meta$",
"^.*.mdown$",
"^.*.pdf$"
],
"headerpaths":[],
"build_settings":
{
"OTHER_LDFLAGS": ["-ObjC"],
"ENABLE_BITCODE": "FALSE",
"SWIFT_VERSION":"5.0",
"LIBRARY_SEARCH_PATHS":["$(SDKROOT)/usr/lib/swift", "$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)", "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME}"],
"LD_RUNPATH_SEARCH_PATHS":["/usr/lib/swift", "$(inherited)", "@executable_path/Frameworks"]
},
"system_capabilities": {
"com.apple.Push":"TRUE"
},
"Info.plist":{
"LSApplicationQueriesSchemes":
[
"fb-messenger-share-api",
"fbapi",
"fbauth2",
"fbshareextension",
"garenagc",
"gop{INTL_GARENA_APP_SDK_ASSIGN_ID}",
"facebook-reels",
"line",
"lineauth2"
],
"NSAppTransportSecurity":
{
"NSAllowsArbitraryLoads":true
},
"CFBundleURLTypes" :
[
{
"CFBundleTypeRole":"Editor",
"CFBundleURLName":"Garena",
"CFBundleURLSchemes":["fb{INTL_FACEBOOK_APP_ID}"]
},
{
"CFBundleTypeRole":"Editor",
"CFBundleURLName":"Garena",
"CFBundleURLSchemes":["gop{INTL_GARENA_APP_SDK_ASSIGN_ID}"]
},
{
"CFBundleTypeRole":"Editor",
"CFBundleURLName":"Google",
"CFBundleURLSchemes":["{INTL_GOOGLE_REVERSED_CLIENT_ID}"]
}
],
"FacebookAppID":"{INTL_FACEBOOK_APP_ID}",
"FacebookClientToken":"{INTL_FACEBOOK_CLIENT_TOKEN}",
"CFBundleName":"{INTL_FACEBOOK_APP_NAME}",
"GOPAppID":"{INTL_GARENA_APP_SDK_ASSIGN_ID}",
"DataDomeKey":"DEFAULT_KEY",
"DataDomeProxyEnabled":false,
"GIDClientID":{INTL_GOOGLE_CLIENT_KEY_IOS}
}在 PLIST 文件中添加 SDK 相关的配置。
- Player Network SDK 1.24 及之后版本
- Player Network SDK 1.24 之前版本
修改
INTLSDK/Source/INTLConfig/Configs/iOS/Plist/INTLGarena.plist
。<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb-messenger-share-api</string>
<string>fbapi</string>
<string>facebook-reels</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>garenagc</string>
<string>gop{INTL_GARENA_APP_SDK_ASSIGN_ID}</string>
<string>line</string>
<string>lineauth2</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Garena</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>gop{INTL_GARENA_APP_SDK_ASSIGN_ID}</string>
</array>
</dict>
<dict>
<key>CFBundleURLName</key>
<string>Garena</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fb{INTL_FACEBOOK_APP_ID}</string>
</array>
</dict>
<dict>
<key>CFBundleURLName</key>
<string>Google</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>{INTL_GOOGLE_REVERSED_CLIENT_ID}</string>
</array>
</dict>
</array>
<key>GOPAppID</key>
<string>{INTL_GARENA_APP_SDK_ASSIGN_ID}</string>
<key>FacebookAppID</key>
<string>{INTL_FACEBOOK_APP_ID}</string>
<key>FacebookClientToken</key>
<string>{INTL_FACEBOOK_CLIENT_TOKEN}</string>
<key>CFBundleName</key>
<string>{INTL_FACEBOOK_APP_NAME}</string>
<key>DataDomeKey</key>
<string>DEFAULT_KEY</string>
<key>DataDomeProxyEnabled</key>
<false/>
<key>GIDClientID</key>
<string>{INTL_GOOGLE_CLIENT_KEY_IOS}</string><key>LSApplicationQueriesSchemes</key>
<array>
<string>fb-messenger-share-api</string>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>garenagc</string>
<string>gop{INTL_GARENA_APP_SDK_ASSIGN_ID}</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Garena</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>gop{INTL_GARENA_APP_SDK_ASSIGN_ID}</string>
</array>
</dict>
<dict>
<key>CFBundleURLName</key>
<string>Garena</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fb{INTL_FACEBOOK_APP_ID}</string>
</array>
</dict>
</array>
<key>GOPAppID</key>
<string>{INTL_GARENA_APP_SDK_ASSIGN_ID}</string>
<key>FacebookAppID</key>
<string>{INTL_FACEBOOK_APP_ID}</string>
<key>FacebookClientToken</key>
<string>{INTL_FACEBOOK_CLIENT_TOKEN}</string>
<key>CFBundleName</key>
<string>{INTL_FACEBOOK_APP_NAME}</string>
<key>DataDomeKey</key>
<string>DEFAULT_KEY</string>
<key>DataDomeProxyEnabled</key>
<false/>在 Xcode 中添加能力。
步骤2:添加 Garena 登录
注册登录相关回调。
- 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++ 事件处理法(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 事件处理法
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}调用
AutoLogin
接口自动登录。- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
在自动登录失败时调用
Login
接口,使玩家手动登录。注意目前,Player Network SDK 支持登录的 iOS Garena 子渠道包括
Guest
、Garena
、Facebook
、Apple
、Google
。通过检查AuthResult
的ExtraJson
字段中返回的子渠道名称查看当前用于登录的子渠道。例如,{"subChannel":"Facebook"}"
.登录 Garena 的 Facebook 子渠道:
- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.Garena, "", "{\"subChannel\":\"Facebook\"}");
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelGarena, "", "{\"subChannel\":\"Facebook\"}");
- 如果已安装应用程序,则打开应用程序登录,否则打开网页登录。
- Garena 登录
permission
参数与其他渠道不同。用户需要输入字符串格式的数字。例如,"2" 或 "4"。权限定义如下:
与游戏后台同步客户端身份验证状态,等待最终验证结果。
步骤3:验收登录功能
在 Player Network SDK 日志中搜索关键字 "AuthResult" 确认渠道名称和 OpenID 是否正确返回。如果正确,则表明集成配置成功,登录功能已成功添加。
如果接入过程中遇到问题,请参见 常见问题。
绑定
由于 Garena 的渠道特性:
- 如果之前已使用过 Facebook 登录,则不能将其用作 Garena 登录的子渠道。否则,将返回错误代码
1013
。 - 成功绑定 Garena 账号后,不能再次绑定。
调用 Bind
接口时,会打开子渠道的应用程序(或网页)以执行登录验证。认证成功后,Player Network SDK 会将子渠道的账号与游客账号绑定。
- Unity
- Unreal Engine
// Log in as guest
INTLAPI.Login(INTLChannel.Garena, "", "{\"subChannel\":\"Guest\"}");
// Bind Logic
INTLAPI.Bind(INTLChannel.Garena, "", "{\"subChannel\":\"Facebook\"}");
// Log in as guest
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelGarena, "", "{\"subChannel\":\"Guest\"}");
// Bind Logic
UINTLSDKAPI::Bind(EINTLLoginChannel::kChannelGarena, "", "{\"subChannel\":\"Facebook\"}");
如果将游客账号绑定到 Garena 失败,游戏必须再次调用 Garena 的游客登录。
调用 Bind
接口后,无论绑定结果如何,Garena SDK 的会话都会被设置为新绑定的渠道(带游客登录状态)。如果再次调用 Bind
接口,绑定将因会话验证失败而失败。因此,建议再次调用游客登录以返回正常的游客登录状态。
如果您在通过 Garena 登录时遇到困难,请参见 Garena 常见问题。