跳到主要内容

iOS

本文旨在介绍如何设置 Garena 身份验证,让您的游戏可以使用 Player Network 登录鉴权服务通过 Garena 渠道登录。

前提条件

1. 设置 Garena 应用

联系 Garena 团队激活应用程序并获取应用程序 ID 和其他相关信息。

要使用 Garena 的平台账号绑定,请请求 Garena 启用 APP_PLATFORM_BIND

  1. 获取 Player Network 控制台登录账号
  2. 为游戏创建新项目,或加入已有项目
  3. 下载 SDK
  4. 接入 SDK
  5. 在 Player Network 控制台添加 Garena 为业务的登录鉴权方式

步骤1:为 Garena 登录配置 SDK

  1. 打开 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_IDSDK_KEY 的值。
    • 设置 LOG_LEVEL = 1LOG_CONSOLE_OUTPUT_ENABLE = 1LOG_FILE_OUTPUT_ENABLE = 1LOG_ENCRYPT_ENABLE = 0LOG_COMPRESS_ENABLE = 0,以便在不加密或压缩输出的情况下输出控制台日志和日志文件。
    • {INTL_GARENA_APP_SDK_ASSIGN_ID} 替换为已注册的 Garena App ID。
    • {INTL_APP_KEY} 替换为已注册的 Garena App Key。
  2. 将 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} 替换为相应的值。

    有关 DateDomeKeyDataDomeProxyEnabled 的配置请参见 Garena: Upgrade to 4.0.21

    注意

    从 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}
    }
  3. 在 Xcode 中添加能力。

    图片:Xcode Setting 1

步骤2:添加 Garena 登录

  1. 注册登录相关回调。

    // 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. 调用 AutoLogin 接口自动登录。

    INTLAPI.AutoLogin();
  3. 在自动登录失败时调用 Login 接口,使玩家手动登录。

    注意

    目前,Player Network SDK 支持登录的 iOS Garena 子渠道包括 GuestGarenaFacebookAppleGoogle。通过检查 AuthResultExtraJson 字段中返回的子渠道名称查看当前用于登录的子渠道。例如,{"subChannel":"Facebook"}".

    登录 Garena 的 Facebook 子渠道:

    INTLAPI.Login(INTLChannel.Garena, "", "{\"subChannel\":\"Facebook\"}");
    • 如果已安装应用程序,则打开应用程序登录,否则打开网页登录。
    • Garena 登录 permission 参数与其他渠道不同。用户需要输入字符串格式的数字。例如,"2" 或 "4"。权限定义如下:

    图片:Garena Permission

  4. 与游戏后台同步客户端身份验证状态,等待最终验证结果。

步骤3:验收登录功能

在 Player Network SDK 日志中搜索关键字 "AuthResult" 确认渠道名称和 OpenID 是否正确返回。如果正确,则表明集成配置成功,登录功能已成功添加。

如果接入过程中遇到问题,请参见 常见问题

绑定

注意

由于 Garena 的渠道特性:

  1. 如果之前已使用过 Facebook 登录,则不能将其用作 Garena 登录的子渠道。否则,将返回错误代码 1013
  2. 成功绑定 Garena 账号后,不能再次绑定。

调用 Bind 接口时,会打开子渠道的应用程序(或网页)以执行登录验证。认证成功后,Player Network SDK 会将子渠道的账号与游客账号绑定。

// Log in as guest
INTLAPI.Login(INTLChannel.Garena, "", "{\"subChannel\":\"Guest\"}");
// Bind Logic
INTLAPI.Bind(INTLChannel.Garena, "", "{\"subChannel\":\"Facebook\"}");
注意

如果将游客账号绑定到 Garena 失败,游戏必须再次调用 Garena 的游客登录。

说明

调用 Bind 接口后,无论绑定结果如何,Garena SDK 的会话都会被设置为新绑定的渠道(带游客登录状态)。如果再次调用 Bind 接口,绑定将因会话验证失败而失败。因此,建议再次调用游客登录以返回正常的游客登录状态。

如果您在通过 Garena 登录时遇到困难,请参见 Garena 常见问题