实时传译
  • iOS : Objective-C
  • Android
  • 云市场简介
  • 产品简介
  • 下载
  • 快速开始
  • 客户端 API
  • 常见错误码
  • 文档中心
  • 实时传译
  • 快速开始
  • 集成 SDK

集成 SDK

更新时间:2023-11-28 18:19

准备环境

在开始集成 ZegoRealtimeTranslation SDK 前,请确保开发环境满足以下要求:

  • Xcode 14.0 或以上版本。
  • iOS 11.0 或以上版本且支持音视频的 iOS 设备(仅支持使用真机)。
  • iOS 设备已经连接到 Internet。

集成 SDK

1 (可选)新建项目

  1. 启动 Xcode,在 “Welcome to Xcode” 窗口中,单击 “Create a new Xcode project” 或选择 “File > New > Project” 菜单,在出现的表单中,选择 iOS 平台,并在 “Application” 下选择 “App”。

  2. 填写表单并选取各个选项来配置项目,单击 “Next”。

    必须提供 “Product Name” 和 “Organization Identify”,用于创建在整个系统中标识 App 的 “Bundle Identify”。

  1. 选择项目存储路径,单击 “Create” 创建项目。

2 导入 SDK

  1. 下载 最新版本的 SDK,下载完成后进行解压。

  2. 请从 zreporter 下载日志上报的 SDK, 用于将 SDK 中的事件上报至后台,用于分析问题。

  3. 打开已解压文件夹,手动将以下 SDK 动态库文件,拷贝到项目目录下。

  • ZegoRealtimeTranslation.xcframework
  • zreporter.xcframework
  1. 打开 Xcode,选择 “File > Add Files to "xxx"(xxx 为项目名)” 菜单,添加以上 SDK 动态库文件到项目。

  2. 选择 “TARGETS > General > Frameworks, Libraries, and Enbedded Content” 菜单,添加 “ZegoRealtimeTranslation.xcframework”,将 “Embed” 设置为 “Embed & Sign”。

    /Pics/iOS/RealtimeTranslation/set_framework_libs.jpg

  3. 选择 “TARGET > General > Deployment Target”,设置 11.0 或以上版本。

    /Pics/iOS/RealtimeTranslation/set_mini_deployments.jpg

  4. 请从 google-proto 下载 google 文件夹以及 googleapis.podspec 文件,解压缩后,将 google 文件夹和 googleapis.podspec 文件拖拽到项目根目录下,googleapis 用于安装 google 语音识别的服务的依赖库,google 文件夹里面存放的是消息发送及接收的 proto 文件。

    /Pics/iOS/RealtimeTranslation/add_google_api.jpg

    googleapis.podspec 文件内容如下:

    Pod::Spec.new do |s|
      s.name     = 'googleapis'
      s.version  = '0.0.1'
      s.license  = 'Apache 2.0'
      s.authors  = { 'Google Inc.' => 'timburks@google.com'}
      s.homepage = 'http://github.com/GoogleCloudPlatform/ios-docs-samples'
      s.source   = { :git => 'https://github.com/GoogleCloudPlatform/ios-docs-samples.git',
                     :tag => '0.0.1' }
      s.summary  = 'Service definitions for Google Cloud Platform APIs'      
    
      s.ios.deployment_target = '7.1'
      s.osx.deployment_target = '10.9'
    
     # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
      s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.6"
    
      # Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
      pods_root = 'Pods'
    
      # Path where Cocoapods downloads protoc and the gRPC plugin.
      protoc_dir = "#{pods_root}/!ProtoCompiler"
      protoc = "#{protoc_dir}/protoc"
      plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin"
    
      # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
      # You can run this command manually if you later change your protos and need to regenerate.  
    
      # The --objc_out plugin generates a pair of .pbobjc.h/.pbobjc.m files for each .proto file.
      s.subspec "Messages" do |ms|
        ms.source_files = "google/**/*.pbobjc.{h,m}"
        ms.header_mappings_dir = "."
        ms.requires_arc = false
        ms.dependency "Protobuf"
      end
    
      # The --objcgrpc_out plugin generates a pair of .pbrpc.h/.pbrpc.m files for each .proto file with
      # a service defined.
      s.subspec "Services" do |ss|
        ss.source_files = "google/**/*.pbrpc.{h,m}"
        ss.header_mappings_dir = "."
        ss.requires_arc = true
        ss.dependency "gRPC-ProtoRPC"
        ss.dependency "#{s.name}/Messages"
      end
    
      s.pod_target_xcconfig = {
        'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1',
          'USER_HEADER_SEARCH_PATHS' => '$SRCROOT/..'
      }
    
    end
  5. 在 Podfile 文件中,添加 ZegoRealtimeTranslation SDK 的第三方依赖。然后在终端 cd 到项目的根目录,并使用 pod install 命令,安装依赖库。由于 google 语音识别的依赖库较大,下载安装容易失败,请确保网络环境良好,最好是安装代理。

    pod 'ZegoExpressEngine/Video'
    # sdk依赖库
    pod 'SocketRocket', '~> 0.6.0'
    pod 'OpenSSL-Universal', '~> 1.0.1.20'
    pod 'MicrosoftCognitiveServicesSpeech-iOS', '~> 1.20'
    pod 'MJExtension', '~> 3.4.1'
    pod 'googleapis', :path => '.'
    pod 'AFNetworking', '~> 4.0.1'
    pod 'GZIP', '~> 1.3.0'
  6. 在 “Pods > TARGETS” 中,找到 gRPC-gRPCCertificates 修改成自己证书和签名。

本篇目录