TapBootstrap 用于 TapSDK 中的内建账户登陆、用户信息获取等功能
- Android
- iOS
- macOS
- Windows
- 安装 UE 4.26 及以上版本
- IOS 12 或更高版本
- Android MinSDK 为 API21 或更高版本
- 下载 TapSDK.zip 解压后将
TapBootstrap
、TapLogin
、TapCommon
文件夹Copy
到项目的Plugins
目录中 - 重启 Unreal Editor
- 打开 编辑 > 插件 > 项目 > TapTap,开启
TapBootstrap
、TapLogin
模块
在 项目设置 > Platform > iOS > Additional Plist data 中可以填入一个字符串,复制以下代码并且替换其中的ClientId
以及授权文案。
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>taptap</string>
<key>CFBundleURLSchemes</key>
<array>
<string>tt{ClientId}</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tapiosdk</string>
<string>tapsdk</string>
</array>
如果有 TapDB
模块,那么还需要加上:
<key>NSUserTrackingUsageDescription<key>
<string>{数据追踪权限申请文案} </string>
在 Project.Build.cs 中添加所需模块:
PublicDependencyModuleNames.AddRange(new string[] { "Core",
"CoreUObject",
"Engine",
"Json",
"InputCore",
"JsonUtilities",
"SlateCore",
"TapCommon",
"TapBootstrap",
"TapLogin"
});
#include "TapBootstrap.h"
#include "TDSUser.h"
TapBootstrap
会把TapLogin
模块一起初始化,如果插件中包含TapDB
并且DBConfig.Enable = true
,那么也会把TapDB
初始化,相关模块无需再次初始化。
FTUConfig Config;
Config.ClientID = ClientID;
Config.ClientToken = ClientToken;
Config.ServerURL = ServerURL;
Config.RegionType = RegionType;
Config.DBConfig.Enable = true; // 如果该项为true,那么会将TapDB一起初始化了
Config.DBConfig.Channel = Channel;
Config.DBConfig.GameVersion = GameVersion;
Config.DBConfig.AdvertiserIDCollectionEnabled = AdvertiserIDCollectionEnabled;
FTapBootstrap::Init(Config);
FTDSUser::FDelegate OnSuccess = FTDSUser::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserSuccessCallBack);
FTUError::FDelegate OnError = FTUError::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserErrorCallBack);
FTDSUser::LoginWithTapTap({TUType::PermissionScope::Profile, TUType::PermissionScope::Friend}, OnSuccess, OnError);
FTDSUser::FDelegate OnSuccess = FTDSUser::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserSuccessCallBack);
FTUError::FDelegate OnError = FTUError::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserErrorCallBack);
FTDSUser::LoginAnonymously(OnSuccess, OnError);
FTDSUser::Logout();
如果是登出状态,获得结果为nullptr
TSharedPtr<FTDSUser> User = FTDSUser::GetCurrentUser()
下面的代码使用 session token
登录一个用户(云端会验证 session token
是否有效):
FTDSUser::FDelegate OnSuccess = FTDSUser::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserSuccessCallBack);
FTUError::FDelegate OnError = FTUError::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserErrorCallBack);
FString Token = ETB_User_SessionToken->GetText().ToString();
FTDSUser::BecomeWithSessionToken(Token, OnSuccess, OnError);
TSharedPtr<FTDSUser> User = FTDSUser::GetCurrentUser();
if (User.IsValid()) {
User->isAuthenticated();
} else {
}
FTDSUser::FDelegate OnSuccess = FTDSUser::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserSuccessCallBack);
FTUError::FDelegate OnError = FTUError::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserErrorCallBack);
const FString Platform = ETB_Login_Platform->GetText().ToString();
TSharedPtr<FJsonObject> AuthData = MakeShared<FJsonObject>();
AuthData->SetStringField("openid", "OPENID");
AuthData->SetStringField("access_token", "ACCESS_TOKEN");
AuthData->SetNumberField("expires_in", 7200);
AuthData->SetStringField("refresh_token", "REFRESH_TOKEN");
AuthData->SetStringField("scope", "SCOPE");
FTDSUser::LoginWithAuthData(Platform, AuthData, OnSuccess, OnError);
FTDSUser::FDelegate OnSuccess = FTDSUser::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserSuccessCallBack);
FTUError::FDelegate OnError = FTUError::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserErrorCallBack);
UserPtr->AssociateWithAuthData(Platform, AuthData, OnSuccess, OnError);
FTDSUser::FDelegate OnSuccess = FTDSUser::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserSuccessCallBack);
FTUError::FDelegate OnError = FTUError::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserErrorCallBack);
UserPtr->DisassociateAuthData(Platform, OnSuccess, OnError);
FString Name = "world";
int From = 0;
int Limit = 10;
FTDSLeaderBoardRanking::FRankingsDelegate OnSuccess = FTDSLeaderBoardRanking::FRankingsDelegate::CreateLambda([](const TArray<FTDSLeaderBoardRanking>& Rankings) {
});
FTUError::FDelegate OnError = FTUError::FDelegate::CreateUObject(this, &UServiceWidgetBootstrap::OnUserErrorCallBack);
FTDSLeaderBoardRanking::QueryTapFriendsLeaderBoard(Name, From, Limit, OnSuccess, OnError);