iOS
本文旨在介绍如何设置 Garena 身份验证,让您的游戏可以使用 Player Network 登录鉴权服务通过 Garena 渠道登录。
前提条件
1. 设置 Garena 应用
联系 Garena 团队激活应用程序并获取应用程序 ID 和其他相关信息。
要使用 Garena 的平台账号绑定,请请求 Garena 启用 APP_PLATFORM_BIND
。
- 获取 Player Network 控制台登录账号。
- 为游戏创建新项目,或加入已有项目。
- 下载 SDK。
- 接入 SDK。
- 在 Player Network 控制台添加 Garena 为业务的登录鉴权方式。
步骤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 相关的配置。
- SDK 1.24 及之后版本
- 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";
}
}