TDLib

TDLib iOS 与 Apple 平台构建

为 iOS、macOS、watchOS、tvOS 和 visionOS 构建 OpenSSL、TDLib 与 XCFramework。

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

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

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

本页内容
  1. 开始之前
  2. 通用 XCFramework 构建示例

开始之前

Apple 平台构建需要匹配 Xcode、SDK、架构与目标平台。xcode-select --install 主要安装命令行工具;iOS 构建仍需完整 Xcode。下面保留原文命令,执行前请先核对当前开发环境。

通用 XCFramework 构建示例

以下说明如何为 iOS、watchOS、tvOS、visionOS 以及 macOS 构建 TDLib。

如果只需要当前架构的 macOS 构建,请查看 TDLib 构建说明生成器。

使用方法可以参考 Swift 示例。

编译 TDLib 需要:

  • 通过 xcode-select --install 或从 Xcode 网站 下载,安装最新 Xcode。为 iOS 构建 TDLib 时,仅安装命令行开发工具并不够。为 watchOS 构建 TDLib 需要 Xcode >= 14.0。
  • 使用 Homebrew 安装其他构建依赖:
brew install gperf cmake coreutils
  • 如果不先为 macOS 构建 TDLib,则必须按以下方式预生成所需源文件:
cd <path to TDLib sources>
mkdir native-build
cd native-build
cmake -DTD_GENERATE_SOURCE_FILES=ON ..
cmake --build .
  • 为 iOS、watchOS、tvOS、visionOS 和 macOS 构建 OpenSSL:
cd <path to TDLib sources>/example/ios
./build-openssl.sh

这里使用 Python Apple support 的脚本,其他 OpenSSL 构建方式也应可用。 Python Apple support 存在当前目录路径含空格时的已知问题,因此需要确保路径中没有空格。 构建好的 OpenSSL 库应放在 third_party/openssl/<platform> 目录中,因为下一步脚本会依赖此位置。

  • 为 iOS、watchOS、tvOS、visionOS 和 macOS 构建 TDLib:
cd <path to TDLib sources>/example/ios
./build.sh

这可能需要一些时间,因为 TDLib 会被构建约 16 次。 按该说明生成的 XCFramework 可用于各目标架构,也可用于模拟器。 这里使用 CMake/iOS.cmake 工具链,其他工具链也可能适用。

构建好的库和 XCFramework 将存放在 tdjson 目录。

所有可用类和方法的文档见 https://core.telegram.org/tdlib/docs。

如果遇到 "error: SDK "appletvsimulator" cannot be located",需要先运行命令 "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer",再运行 ./build.sh。

继续阅读 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.