tencent cloud

文档反馈

最后更新时间:2024-06-25 10:43:44
    本文将介绍如何集成 TUIKit 组件。
    说明:
    从 5.7.1435 版本开始,TUIKit 支持模块化集成,支持了经典版 UI,您可以根据自己的需求集成所需模块。
    从 6.9.3557 版本开始,TUIKit 新增了全新的简约版 UI。
    您可以根据需求自由选择经典版或简约版 UI 组件。如果您还不了解各个界面库的效果,可以查阅文档 TUIKit 界面库介绍

    开发环境要求

    Xcode 10 及以上
    iOS 9.0 及以上

    CocoaPods 集成

    1. 安装 CocoaPods。 在终端窗口中输入如下命令(需要提前在 Mac 中安装 Ruby 环境):
    sudo gem install cocoapods
    2. 创建 Podfile 文件。 进入项目所在路径输入以下命令行,之后项目路径下会出现一个 Podfile 文件。
    pod init
    3. 根据业务需求在 Podfile 中添加对应的 TUIKit 组件。组件之间相互独立,添加或删除均不影响工程编译。您可以按需选择不同的 Podfile 集成方式:
    远程 CocoaPods 集成
    DevelopmentPods 本地集成
    以上两种集成方式的优缺点如下表所示:
    集成方式
    适合场景
    优点
    缺点
    远程 CocoaPods 集成
    适合无源码修改时的集成。
    当 TUIKit 有版本更新时,您只需再次 Pod update 即可完成更新。
    当您有源码修改,使用 Pod update 更新时,新版本的 TUIKit 会覆盖您的修改。
    本地 DevelopmentPods 集成
    适合有涉及源码自定义修改的客户。
    当您有自己的 git 仓库时,可以跟踪修改。修改源码后,使用 Pod update 更新其他远程 Pod 库时,不会覆盖您的修改。
    您需要手动将 TUIKit 源码覆盖您本地 TUIKit 文件夹进行更新。

    远程 CocoaPods 集成

    您可以在 Podfile 中按需添加组件库:
    简约版
    经典版
    # Uncomment the next line to define a global platform for your project
    # ...
    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '13.0'
    # Prevent `*.xcassets` in TUIKit from conflicting with your project
    install! 'cocoapods', :disable_input_output_paths => true
    
    # Replace `your_project_name` with your actual project name
    target 'your_project_name' do
    # Comment the next line if you don't want to use dynamic frameworks
    # TUIKit components are dependent on static libraries. Therefore, you need to mask the configuration.
    # use_frameworks!
    
    # Enable modular headers as needed. Only after you enable modular headers, the Pod module can be imported using @import.
    # use_modular_headers!
    
    # Integrate the chat feature
    pod 'TUIChat/UI_Minimalist'
    # Integrate the conversation list feature
    pod 'TUIConversation/UI_Minimalist'
    # Integrate the relationship chain feature
    pod 'TUIContact/UI_Minimalist'
    # Integrate the group feature
    pod 'TUIGroup/UI_Minimalist'
    # Integrate the search feature (To use this feature, you need to purchase the Premium edition)
    pod 'TUISearch/UI_Minimalist'
    # Integrate the audio/video call feature
    pod 'TUICallKit'
    # Integrate Translation Plugin, supported starting from version 7.2 (Value-added feature activation required, please contact Tencent Cloud Business to activate)
    pod 'TUITranslationPlugin'
    # Integrate Session Tagging Plugin, supported starting from version 7.3
    pod 'TUIConversationMarkPlugin'
    # Integrate Speech-to-Text Plugin, supported starting from version 7.5
    pod 'TUIVoiceToTextPlugin'
    # Integrate message push plugin, supported starting from version 7.6
    pod 'TIMPush'
    end
    
    #Pods config
    post_install do |installer|
    installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
    #Fix Xcode14 Bundle target error
    config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
    config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
    config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
    config.build_settings['ENABLE_BITCODE'] = "NO"
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "13.0"
    #Fix Xcode15 other links flag -ld64
    xcode_version = `xcrun xcodebuild -version | grep Xcode | cut -d' ' -f2`.to_f
    if xcode_version >= 15
    xcconfig_path = config.base_configuration_reference.real_path
    xcconfig = File.read(xcconfig_path)
    if xcconfig.include?("OTHER_LDFLAGS") == false
    xcconfig = xcconfig + "\\n" + 'OTHER_LDFLAGS = $(inherited) "-ld64"'
    else
    if xcconfig.include?("OTHER_LDFLAGS = $(inherited)") == false
    xcconfig = xcconfig.sub("OTHER_LDFLAGS", "OTHER_LDFLAGS = $(inherited)")
    end
    if xcconfig.include?("-ld64") == false
    xcconfig = xcconfig.sub("OTHER_LDFLAGS = $(inherited)", 'OTHER_LDFLAGS = $(inherited) "-ld64"')
    end
    end
    File.open(xcconfig_path, "w") { |file| file << xcconfig }
    end
    end
    end
    end
    # Uncomment the next line to define a global platform for your project
    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '13.0'
    # Prevent `*.xcassets` in TUIKit from conflicting with your project
    install! 'cocoapods', :disable_input_output_paths => true
    
    # Replace `your_project_name` with your actual project name
    target 'your_project_name' do
    # Comment the next line if you don't want to use dynamic frameworks
    # TUIKit components are dependent on static libraries. Therefore, you need to mask the configuration.
    # use_frameworks!
    
    # Enable modular headers as needed. Only after you enable modular headers, the Pod module can be imported using @import.
    # use_modular_headers!
    
    # Integrate the chat feature
    pod 'TUIChat/UI_Classic'
    # Integrate the conversation list feature
    pod 'TUIConversation/UI_Classic'
    # Integrate the relationship chain feature
    pod 'TUIContact/UI_Classic'
    # Integrate the group feature
    pod 'TUIGroup/UI_Classic'
    # Integrate the search feature (To use this feature, you need to purchase the Premium edition)
    pod 'TUISearch/UI_Classic'
    # Integrate the audio/video call feature
    pod 'TUICallKit'
    # Integrate Voting Plugin, supported starting from version 7.1
    pod 'TUIPollPlugin'
    # Integrate Group Chain Plugin, supported starting from version 7.1
    pod 'TUIGroupNotePlugin'
    # Integrate Translation Plugin, supported starting from version 7.2 (Value-added feature activation required, please contact Tencent Cloud Business to activate)
    pod 'TUITranslationPlugin'
    # Integrate Session Grouping Plugin, supported starting from version 7.3
    pod 'TUIConversationGroupPlugin'
    # Integrate Session Tagging Plugin, supported starting from version 7.3
    pod 'TUIConversationMarkPlugin'
    # Integrate Speech-to-Text Plugin, supported starting from version 7.5
    pod 'TUIVoiceToTextPlugin'
    # Integrate Customer Service Plugin, supported starting from version 7.6
    pod 'TUICustomerServicePlugin'
    # Integrate Bot Plugin, supported starting from version 7.7
    pod 'TUIChatBotPlugin'
    # Integrate message push plugin, supported starting from version 7.6
    pod 'TIMPush'
    
    end
    
    #Pods config
    post_install do |installer|
    installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
    #Fix Xcode14 Bundle target error
    config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
    config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
    config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
    config.build_settings['ENABLE_BITCODE'] = "NO"
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "13.0"
    #Fix Xcode15 other links flag -ld64
    xcode_version = `xcrun xcodebuild -version | grep Xcode | cut -d' ' -f2`.to_f
    if xcode_version >= 15
    xcconfig_path = config.base_configuration_reference.real_path
    xcconfig = File.read(xcconfig_path)
    if xcconfig.include?("OTHER_LDFLAGS") == false
    xcconfig = xcconfig + "\\n" + 'OTHER_LDFLAGS = $(inherited) "-ld64"'
    else
    if xcconfig.include?("OTHER_LDFLAGS = $(inherited)") == false
    xcconfig = xcconfig.sub("OTHER_LDFLAGS", "OTHER_LDFLAGS = $(inherited)")
    end
    if xcconfig.include?("-ld64") == false
    xcconfig = xcconfig.sub("OTHER_LDFLAGS = $(inherited)", 'OTHER_LDFLAGS = $(inherited) "-ld64"')
    end
    end
    File.open(xcconfig_path, "w") { |file| file << xcconfig }
    end
    end
    end
    end
    
    说明
    1. 如果您直接 pod 'TUIChat',不指定经典版或简约版,默认会集成两套版本 UI 组件。
    2. 经典版和简约版 UI 不能混用,集成多个组件时,您必须同时全部选择经典版 UI 或简约版 UI。例如,经典版 TUIChat 组件必须与经典版 TUIConversationTUIContactTUIGroup 组件搭配使用。同理,简约版 TUIChat 组件必须与简约版 TUIConversationTUIContactTUIGroup 组件搭配使用。
    3. 如果您使用的是 Swift,请开启 use_modular_headers! ,并将头文件引用改成 @import 模块名形式引用。
    Podfile 修改完毕后,执行以下命令,安装 TUIKit 组件。
    pod install
    如果无法安装 TUIKit 最新版本,执行以下命令更新本地的 CocoaPods 仓库列表。
    pod repo update
    之后执行以下命令,更新组件库的 Pod 版本。
    pod update
    集成全部的 TUIKit 组件后的项目结构:
    
    注意:
    若您操作遇到错误,可查阅文末的常见问题。

    本地 DevelopmentPods 源码集成

    1. 从 GitHub 下载 TUIKit 源码。直接拖入您的工程目录下:
    
    2. 修改您 Podfile 中每个组件的本地路径。path 是 TUIKit 文件夹相对于您工程 Podfile 文件的位置,常见的有:
    TUIKit 文件夹位于您工程 Podfile 文件父目录pod 'TUICore', :path => "../TUIKit/TUICore"
    TUIKit 文件夹位于您工程 Podfile 文件当前目录pod 'TUICore', :path => "/TUIKit/TUICore"
    TUIKit 文件夹位于您工程 Podfile 文件子目录 pod 'TUICore', :path => "./TUIKit/TUICore"
    
    以 TUIKit 文件夹位于您工程 Podfile 文件父目录为例:
    DevelopmentPodfile
    ment# Uncomment the next line to define a global platform for your project
    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '13.0'
    install! 'cocoapods', :disable_input_output_paths => true
    
    # Replace `your_project_name` with your actual project name
    target 'your_project_name' do
    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
    use_frameworks!
    use_modular_headers!
    
    # Note: To perform upgrade when using a local integration solution, you need to access
    # https://github.com/TencentCloud/TIMSDK/tree/master/iOS/TUIKit
    # to obtain the latest component code, and place it in the local specified directory, such as /TIMSDK/ios/TUIKit/TUICore.
    # Note: When custom modifications conflict with remote changes, you need to manually merge them to resolve conflicts.
    # Integrate the basic library (required)
    pod 'TUICore', :path => "../TUIKit/TUICore"
    pod 'TIMCommon', :path => "../TUIKit/TIMCommon"
    # Integrate TUIKit components (optional)
    # Integrate the chat feature
    pod 'TUIChat', :path => "../TUIKit/TUIChat"
    # Integrate the conversation list feature
    pod 'TUIConversation', :path => "../TUIKit/TUIConversation"
    # Integrate the relationship chain feature
    pod 'TUIContact', :path => "../TUIKit/TUIContact"
    # Integrate the group feature
    pod 'TUIGroup', :path => "../TUIKit/TUIGroup"
    # Integrate the search feature (To use this feature, you need to purchase the Ultimate edition)
    pod 'TUISearch', :path => "../TUIKit/TUISearch"
    # Integrate the audio/video call feature
    pod 'TUICallKit'
    # Integrate the video conference feature
    pod 'TUIRoomKit'
    # Integrate the TUIKitPlugin plugin (optional)
    # Note: The TUIKitPlugin plugin version must be the same as the TUICore version.
    # Ensure that the plugin version matches spec.version in "../TUIKit/TUICore/TUICore.spec".
    # Integrate the voting plugin, supported from version 7.1
    pod 'TUIPollPlugin', '7.6.5011'
    # Integrate the group chain plugin, supported from version 7.1
    pod 'TUIGroupNotePlugin', '7.6.5011'
    # Integrate translation plugin, supported from version 7.2 (Value-added feature activation is required. Please contact Tencent Cloud sales)
    pod 'TUITranslationPlugin', '7.6.5011'
    # Integrate the session grouping plugin, supported from version 7.3
    pod 'TUIConversationGroupPlugin', '7.6.5011'
    # Integrate the session tagging plugin, supported from version 7.3
    pod 'TUIConversationMarkPlugin', '7.6.5011'
    # Integrate the offline push feature
    pod 'TIMPush'
    # Other Pods
    pod 'MJRefresh'
    pod 'Masonry'
    end
    #Pods config
    post_install do |installer|
    installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
    #Fix Xcode14 Bundle target error
    config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
    config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
    config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
    config.build_settings['ENABLE_BITCODE'] = "NO"
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "13.0"
    #Fix Xcode15 other links flag -ld64
    xcode_version = `xcrun xcodebuild -version | grep Xcode | cut -d' ' -f2`.to_f
    if xcode_version >= 15
    xcconfig_path = config.base_configuration_reference.real_path
    xcconfig = File.read(xcconfig_path)
    if xcconfig.include?("OTHER_LDFLAGS") == false
    xcconfig = xcconfig + "\\n" + 'OTHER_LDFLAGS = $(inherited) "-ld64"'
    else
    if xcconfig.include?("OTHER_LDFLAGS = $(inherited)") == false
    xcconfig = xcconfig.sub("OTHER_LDFLAGS", "OTHER_LDFLAGS = $(inherited)")
    end
    if xcconfig.include?("-ld64") == false
    xcconfig = xcconfig.sub("OTHER_LDFLAGS = $(inherited)", 'OTHER_LDFLAGS = $(inherited) "-ld64"')
    end
    end
    File.open(xcconfig_path, "w") { |file| file << xcconfig }
    end
    end
    end
    end
    3. Podfile 修改完毕后,执行以下命令,安装本地 TUIKit 组件。示例:
    pod install
    注意:
    1. 使用本地集成方案时,如需升级时需要从 Github 获取最新的组件代码,覆盖您本地项目的 TUIKit 目录。
    2. 当私有化修改和远端有冲突时,需要手动合并,处理冲突。
    3. TUIKit 插件需要依赖 TUICore 的版本,请确保插件版本和 "../TUIKit/TUICore/TUICore.spec" 中的 spec.version 一致。

    第三方库依赖

    TUIKit 依赖的第三方库的最低版本如下,如果您的版本较低,请升级到最新版本。
    - Masonry (1.1.0)
    - MJExtension (3.4.1)
    - MJRefresh (3.7.5)
    - ReactiveObjC (3.1.1)
    - SDWebImage (5.18.11):
    - SDWebImage/Core (= 5.18.11)
    - SDWebImage/Core (5.18.11)
    - SnapKit (5.6.0)
    - SSZipArchive (2.4.3)

    构建基础界面

    集成 TUIKit 完成后,如果您想要继续构建聊天、会话等基础界面,请参考文档:构建聊天界面构建会话列表等。

    常见问题

    Xcode15 常见问题

    集成时报错 [Xcodeproj] Unknown object version (60). (RuntimeError)
    
    使用 Xcode15 创建新工程来集成 TUIKit 时,输入 pod install 后,可能会遇到此问题,原因是使用了较旧版本的 CocoaPods ,此时有两种解决办法:
    解决方式一: 修改 Xcode 工程的 Project Format 版本为 Xcode13.0。
    
    解决方式二: 升级本地的 CocoaPods 版本,升级方式本文不再赘述。
    Assertion failed: (false && "compact unwind compressed function offset doesn't fit in 24 bits"), function operator(), file Layout.cpp.
    
    或是使用 XCode15 集成 TUIRoom 时,因最新链接器导致 TUIRoomEngine 的符号冲突,都属于该问题。
    
    解决方式:修改链接器配置。在 Build Settings 中的 Other Linker Flags 中添加 -ld64
    
    Rosetta 模拟器问题
    使用苹果芯片(m1\\m2等系列芯片)时会遇到这种弹框。原因是包括 SDWebImage 在内的三方库,并未支持 xcframework。不过苹果依旧给出了适配办法,就是在模拟器上开启 Rosetta 设置, 一般情况下编译时会自动弹出 Rosetta 选项。
    
    Xcode 15 开发者沙盒选项报错 Sandbox: bash(xxx) deny(1) file-write-create
    
    当您使用 Xcode 15 创建一个新工程时, 可能会因为此选项导致编译运行失败,建议您关闭此选项。
    

    CocoaPods 常见问题

    使用远端集成时,Pod 依赖版本不匹配问题
    若您使用远端 CocoaPods 集成时,出现 Podfile.lock 和 插件依赖的 TUICore 版本不一致时,
    此时请删除 Podfile.lock 文件, 并使用 pod repo update 更新本地代码仓库, 之后使用 pod update 重新更新即可。
    
    使用本地集成时,Pod 依赖版本不匹配问题
    若您使用本地 DevelopmentPods 集成时出现插件依赖的 TUICore 版本较新,但本地 Pod 依赖的版本号是 1.0.0 ,
    此时请您参考 Podfile_localTUICore.spec 修改。插件需要跟随版本,需要和 TUICore.spec 中一致。
    第一次使用本地集成时,建议您下载我们的示例 Demo 工程,将 Podfile 文件内容替换为 Podfile_local 的内容,执行 Pod update 后相互参照。
    

    上架常见问题

    上架 Appstore 时打包失败,提示 Unsupported Architectures。
    问题现象如下图,打包时提示 ImSDK_Plus.framework 中包含了 Appstore 不支持的 x86_64 模拟器版本。该问题是由于 SDK 为了方便开发者调试,发布时会默认带上模拟器版本。
    
    您可以按照下面的步骤,在打包时去掉模拟器版本:
    1.1 选中您工程的 Target,并点击 Build Phases 选项,在当前面板中添加 Run Script
    
    1.2 在新增的 Run Script 中,添加如下脚本:
    #!/bin/sh
    
    # Strip invalid architectures
    strip_invalid_archs() {
    binary="$1"
    echo "current binary ${binary}"
    # Get architectures for current file
    archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)"
    stripped=""
    for arch in $archs; do
    if ! [[ "${ARCHS}" == *"$arch"* ]]; then
    if [ -f "$binary" ]; then
    # Strip non-valid architectures in-place
    lipo -remove "$arch" -output "$binary" "$binary" || exit 1
    stripped="$stripped $arch"
    fi
    fi
    done
    if [[ "$stripped" ]]; then
    echo "Stripped $binary of architectures:$stripped"
    fi
    }
    
    APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
    
    # This script loops through the frameworks embedded in the application and
    # removes unused architectures.
    find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
    do
    FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
    FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
    echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
    strip_invalid_archs "$FRAMEWORK_EXECUTABLE_PATH"
    done
    

    TUICallKit 常见问题

    TUICallKit 和自己集成的音视频库冲突了?
    腾讯云的 音视频库 不能同时集成,可能存在符号冲突,可以按照下面的场景处理。
    1.1 如果您使用了 TXLiteAVSDK_TRTC 库,不会发生符号冲突。可直接在 Podfile 文件中添加依赖:
    pod 'TUICallKit'
    1.2 如果您使用了 TXLiteAVSDK_Professional 库,会产生符号冲突。您可在 Podfile 文件中添加依赖:
    pod 'TUICallKit/Professional'
    1.3 如果您使用了TXLiteAVSDK_Enterprise 库,会产生符号冲突。建议升级到TXLiteAVSDK_Professional 后使用TUICallKit/Professional
    通话邀请的超时时间默认是多久?
    通话邀请的默认超时时间是 30 秒。
    在邀请超时时间内,被邀请者如果离线再上线,能否立即收到邀请?
    1.1 如果是单聊通话邀请,被邀请者离线再上线可以收到通话邀请,TUIKit 内部会自动唤起通话邀请界面。
    1.2 如果是群聊通话邀请,被邀请者离线再上线后会自动拉取最近 30 秒内的邀请,TUIKit 会自动唤起群通话界面。

    联系我们

    如果您对本文有疑问,欢迎加入Telegram 技术交流群,您将获得可靠的技术支持。
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持