本文主要介绍如何快速地将腾讯云 IM SDK(Unreal Engine)集成到您的项目中,只要按照如下步骤进行配置,就可以完成 SDK 的集成工作。
建议 Unreal Engine 4.27.1 及以上版本。
开发端 | 环境 |
---|---|
Android | |
iOS & macOS | |
Windows |
下载 SDK 及配套的 SDK 源码。
把项目中的 IM SDK 文件夹拷贝到您项目中的 Source/[project_name] 目录下,其中 [project_name] 表示你项目的名称。
编辑你项目中的 [project_name].Build.cs文件。添加下面函数:
// 加载各个平台IM底层库
private void loadTIMSDK(ReadOnlyTargetRules Target) {
string _TIMSDKPath = Path.GetFullPath(Path.Combine(ModuleDirectory, "TIMSDK"));
bEnableUndefinedIdentifierWarnings = false;
PublicIncludePaths.Add(Path.Combine(_TIMSDKPath, "include"));
if (Target.Platform == UnrealTargetPlatform.Android) {
PrivateDependencyModuleNames.AddRange(new string[] { "Launch" });
AdditionalPropertiesForReceipt.Add(new ReceiptProperty("AndroidPlugin", Path.Combine(ModuleDirectory, "TIMSDK", "Android", "APL_armv7.xml")));
string Architecture = "armeabi-v7a";
// string Architecture = "arm64-v8a";
// string Architecture = "armeabi";
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory,"TIMSDK", "Android", Architecture, "libImSDK.so"));
}
else if (Target.Platform == UnrealTargetPlatform.IOS) {
PublicAdditionalLibraries.AddRange(
new string[] {
"z","c++",
"z.1.1.3",
"sqlite3",
"xml2"
}
);
PublicFrameworks.AddRange(new string[]{
"Security",
"AdSupport",
"CoreTelephony",
"CoreGraphics",
"UIKit"
});
PublicAdditionalFrameworks.Add(new UEBuildFramework("ImSDK_CPP",_TIMSDKPath+"/ios/ImSDK_CPP.framework.zip", ""));
}
else if(Target.Platform == UnrealTargetPlatform.Mac) {
PublicAdditionalLibraries.AddRange(new string[] {
"resolv",
"z",
"c++",
"bz2",
"sqlite3",
});
PublicFrameworks.AddRange(
new string[] {
"AppKit",
"Security",
"CFNetwork",
"SystemConfiguration",
});
PublicFrameworks.Add(Path.Combine(_TIMSDKPath, "Mac", "Release","ImSDKForMac_CPP.framework"));
}
else if (Target.Platform == UnrealTargetPlatform.Win64) {
PublicAdditionalLibraries.Add(Path.Combine(_TIMSDKPath, "win64", "Release","ImSDK.lib"));
PublicDelayLoadDLLs.Add(Path.Combine(_TIMSDKPath, "win64", "Release", "ImSDK.dll"));
RuntimeDependencies.Add("$(BinaryOutputDir)/ImSDK.dll", Path.Combine(_TIMSDKPath, "win64", "Release", "ImSDK.dll"));
}
}
在 [project_name].Build.cs 文件调用该函数:
到目前为止你已经集成了 IM SDK。可在你的 cpp 文件中使用 IM 的能力了。#include "V2TIMManager.h"
// 获取sdk单例对象
V2TIMManager* timInstance = V2TIMManager::GetInstance();
// 获取sdk版本号
V2TIMString timString = timInstance->GetVersion();
// 初始化sdk
V2TIMSDKConfig timConfig;
timConfig.initPath = static_cast<V2TIMString>("D:\\");
timConfig.logPath = static_cast<V2TIMString>("D:\\");
bool isInit = timInstance->InitSDK(SDKAppID, timConfig);
更多接口介绍,请参见 API 概览。
本页内容是否解决了您的问题?