TDLib

TDLib UWP 开发指南

构建 Universal Windows Platform SDK、Visual Studio 扩展或 NuGet 包,并运行 C# 示例。

GetTGAPI 编辑团队更新于
TDLib 文档核对日期

来源版本 a94b83d67ab4 · TDLib contributors · BSL-1.0

依据官方资料整理,由 GetTGAPI 独立维护。 文档目录与术语表 →

本页内容
  1. 开始之前
  2. TDLib Universal Windows Platform 示例
  3. 构建 SDK
  4. 使用示例

开始之前

此页保留 UWP 项目的官方说明,适合维护既有 UWP 应用。脚本参数请以相应提交的 build.ps1 定义为准;原文说明与示例中的 vcpkg 参数拼写不完全一致,命令示例保留原样。

TDLib Universal Windows Platform 示例

本示例说明如何构建适用于 Universal Windows Platform 的 TDLib SDK,以及如何从 C# 使用它。

构建 SDK

  • 下载并安装带有 Windows 10 SDK 的 Microsoft Visual Studio 2017+。原文建议使用可获取的最新 Microsoft Visual Studio 和 Windows 10 SDK。
  • 下载并安装 CMake,要求 CMake 3.13 或更新版本。
  • 使用 vcpkg 为所有 UWP 架构安装 zlib 和 openssl,并为 x86 安装 gperf:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
git checkout c3867e714dd3a51c272826eea77267876517ed99
.\bootstrap-vcpkg.bat
.\vcpkg.exe install gperf:x86-windows openssl:arm64-uwp openssl:x64-uwp openssl:x86-uwp zlib:arm64-uwp zlib:x64-uwp zlib:x86-uwp
  • (可选,用于生成 XML 文档。)下载 PHP,将 php.exe 所在路径加入 PATH 环境变量。
  • 下载并安装 7-Zip 压缩工具;build.ps1 脚本使用它创建 Telegram.Td.UWP Visual Studio 扩展。将 7z.exe 所在路径加入 PATH 环境变量。也可以通过 build.ps1 的 -compress winrar 选项使用 WinRAR,或通过 -compress zip 使用 zip。
  • 使用提供的 build.ps1 脚本构建 TDLib。为覆盖多个平台及 Debug、Release 配置,需要构建 6 次,可能耗时数小时。以 -vcpkg-root 参数传入 vcpkg.exe 路径,例如:
powershell -ExecutionPolicy ByPass .\build.ps1 -vcpkg_root C:\vcpkg

如果需要从头重新构建,先调用 .\build.ps1 -vcpkg_root C:\vcpkg -mode clean。

  • 安装 Visual Studio 扩展 "TDLib for Universal Windows Platform"。它由上一步 build.ps1 脚本生成,位于 build-uwp\vsix\tdlib.vsix。

之后,在 Visual Studio 中构建的任意 UWP 项目都可以使用 TDLib。

也可以在调用 .\build.ps1 时加入 -nupkg 选项,将 TDLib 构建为 NuGet 包。生成的包将放入 build-uwp\nupkg 目录。

使用示例

app/ 目录包含一个简单的 C# Universal Windows Platform 应用示例。用 Visual Studio 2015 或更新版本打开并运行即可。

继续阅读 TDLib 总览与构建。需要应用凭证时,可参考 API ID 与 Hash 申请流程;申请遇到 ERROR,可通过 GetTGAPI 客服 沟通。

原文许可与归属 · BSL-1.0

TDLib contributors · 完整许可文件

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.