ZegoUIKit 2.11.7

ZegoUIKit 2.11.7

ZEGOwukunzhengling 维护。



 
依赖项
ZegoExpressEngine~> 3.14.5
ZegoPluginAdapter>= 2.4.0
 

ZegoUIKit 2.11.7

  • ZEGOCLOUND

如何将 ZegoUIKit 集成到您的项目中

在此文档中,我们创建一个新的 iOS 应用项目来介绍如何集成

create_new_project

creare_new_project_1

安装 Pods

  1. 打开终端,导航到 Demo 文件夹并运行 pod init 命令。

init_podfile

  1. 为 ZegoUIKit 添加依赖项:pod 'ZegoExpressEngine'

edit_podfile

add_express

  1. 运行 pod install 命令以安装所有所需的依赖项。

    pod_install

添加 ZegoUIKit 到项目中

  1. 在 Xcode 中打开 .xcworkspace 文件

    open_xcworkspace
  2. 解压 ZegoUIKit.zip 并将其放置在与项目根目录相同的级别†

add_uikit_sdk_project

  1. 在 info.plist 文件中配置相机和麦克风权限支持

    config_device_permissions

集成 ZegoUIKitPrebuiltCall

class ViewController: UIViewController {

  override func viewDidLoad() {

	   super.viewDidLoad()
	   // Do any additional setup after loading the view.
  }

  @IBAction func startCall(_ sender: Any) {
    let config: ZegoUIkitPrebuiltCallConfig = ZegoUIkitPrebuiltCallConfig()
    let callVC: ZegoUIKitPrebuiltCallVC = ZegoUIKitPrebuiltCallVC.init(YOUR_APPID, appSign: YOUR_APP_Sign, userID: "userID", userName: "UserName", callID: "callID", config: config)
    callVC.modalPresentationStyle = .fullScreen
    callVC.delegate = self
    self.present(callVC, animated: true, completion: nil)     
  }
}

extension ViewController: ZegoUIKitPrebuiltCallVCDelegate {
    func onHangUp(_ isHandup: Bool) {
        // Triggered when hanging up 
    }
    
    func getForegroundView(_ userInfo: ZegoUIkitUser?) -> UIView? {
        // You can add your custom ForegroundView on top of AudioVideoView here
    }
    
    func onOnlySelfInRoom() {
        //You're the only person on the line right now
    }
    
}

功能提示

  1. 支持点击无响应区域隐藏菜单栏
  2. 支持显示音频通话模式中的声音波
  3. 支持点击小视图交换为大视图
  4. 支持拖动小视图位置

更多功能请参阅高级配置属性列表

自定义

  1. 自定义音频视频视图的背景图

    //Set before initializing ZegoUIKitPrebuiltCallVC
    let config: ZegoUIkitPrebuiltCallConfig = ZegoUIkitPrebuiltCallConfig()
    let layoutConfig: ZegoLayout = ZegoLayout()
    let pictureInPictureConfig: ZegoLayoutPictureInPictureConfig = ZegoLayoutPictureInPictureConfig()
    pictureInPictureConfig.bigViewBackgroundImage = YOUR_CUSTOM_IMAGE// set your custom image
    pictureInPictureConfig.smallViewBackgroundImage = YOUR_CUSTOM_IMAGE // set your custom image
    layoutConfig.config = pictureInPictureConfig
    layoutConfig.mode = .pictureInPicture
    config.layout = layoutConfig
  2. 自定义音频视频视图的背景色

    //Set before initializing ZegoUIKitPrebuiltCallVC
    let config: ZegoUIkitPrebuiltCallConfig = ZegoUIkitPrebuiltCallConfig()
    let layoutConfig: ZegoLayout = ZegoLayout()
    let pictureInPictureConfig: ZegoLayoutPictureInPictureConfig = ZegoLayoutPictureInPictureConfig()
    pictureInPictureConfig.bigViewBackgroundColor = YOUR_CUSTOM_IMAGE// set your custom image
    pictureInPictureConfig.smallViewBackgroundColor = YOUR_CUSTOM_IMAGE // set your custom image
    layoutConfig.config = pictureInPictureConfig
    layoutConfig.mode = .pictureInPicture
    config.layout = layoutConfig
  3. 自定义音频视频视图的前景

    class ViewController: UIViewController {
      
      func startCall() {
        let callVC: ZegoUIKitPrebuiltCallVC = ZegoUIKitPrebuiltCallVC.init(YOUR_APPID, appSign: "YOUR_APP_Sign", 		 		userID: "userID", userName: "UserName", callID: "callID", config: config)
    		 callVC.delegate = self //set delegate
      }
      
    }
    
    //Implementing the proxy method
    extension ViewController: ZegoUIKitPrebuiltCallVCDelegate {
        func getForegroundView(_ userInfo: ZegoUIkitUser?) -> UIView? {
            let customView: UIView = UIView()
            return customView
        }
    }
  4. 自定义菜单栏按钮

    //Set before initializing ZegoUIKitPrebuiltCallVC
    let config: ZegoUIkitPrebuiltCallConfig = ZegoUIkitPrebuiltCallConfig()
    config.menuBarButtons = [.quitButton,.swtichAudioOutputButton,.toggleMicrophoneButton]
  5. 将系统按钮添加到菜单栏

    let callVC: ZegoUIKitPrebuiltCallVC
    let button: UIButton = UIButton()
    button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
    callVC.addButtonToMenuBar(button)
    
    @objc func buttonClick() {
         // button click event
    }
  6. 将组件按钮添加到菜单栏

    let callVC: ZegoUIKitPrebuiltCallVC
    let button: ZegoLeaveButton = ZegoLeaveButton()
    callVC.addButtonToMenuBar(button)

高级配置

您可以修改更多的高级配置属性,例如 config.turnOnCameraWhenJoining = false;,用法示例

//Set before initializing ZegoUIKitPrebuiltCallVC
let config: ZegoUIkitPrebuiltCallConfig = ZegoUIkitPrebuiltCallConfig()
config.turnOnCameraWhenjoining = false
let callVC: ZegoUIKitPrebuiltCallVC =  ZegoUIKitPrebuiltCallVC.init(YOUR_APPID, appSign: "YOUR_APP_Sign", userID: "userID", userName: "UserName", callID: "callID", config: config)

高级配置属性列表

变量名 类型 默认值 注释
turnOnCameraWhenJoining Bool true 是否默认启用摄像头,默认值为true
turnOnMicrophoneWhenJoining Bool true 是否默认启用麦克风,默认值为true
useSpeakerWhenJoining Bool false 是否默认使用扬声器,默认值为false;
showSoundWaveOnAudioView Bool true 在语音模式下是否显示围绕头像的声波
showMicrophoneStateOnView Bool true 用于控制是否在预置层上显示默认的MicrophoneStateIcon。
showCameraStateOnView Bool true 用于控制是否在VideoView上显示默认的CameraStateIcon。
showUserNameOnView Bool true 用于控制是否在VideoView上显示默认的UserNameLabel。
layout ZegoLayout ZegoLayoutPictureInPictureConfig() 默认布局为画中画布局
hangUpConfirmInfo ZegoHangUpConfirmDialogInfo ZegoHangUpConfirmDialogInfo() 退出时的警告对话框信息。如果确认信息不为空,APP将弹出一个警告对话框
isMenuBarHideAutomatically Bool true 如果为true,菜单栏将在静止5秒后折叠
isMenuBarHideByClick Bool true 如果为true,点击空白区域时菜单栏会折叠
menuBarButtons [ZegoMenuBarButtonType] [
.toggleCameraButton,
.toggleMicrophoneButton,
.quitButton,
.swtichAudioOutputButton,
.swtichCameraFacingButton

]
这些按钮将显示在菜单栏上,按列表顺序排列
menuBarButtonsLimitedCount Int 5 菜单栏上显示的项数限制,如果超过此数,将显示More按钮

高级布局配置

每个布局都有一组可配置的参数供您选择

ZegoLayoutPictureInPictureConfig

变量名 类型 默认值 注释
isSmallViewDraggable Bool false 小视图是否可拖动。
showSelfViewWithVideoOnly Bool false 值为true表示仅在摄像头开启时显示小视图。否则,小视图始终存在。如果您在大视图模式下,此参数不起作用
smallViewBackgroundColor UIColor gray 语音通话时小视图的背景颜色
bigViewBackgroundColor UIColor gray 语音通话时大视图的背景颜色
smallViewBackgroundImage UIImage nil 语音通话时,小视图的背景图比背景颜色优先级高
bigViewBackgroundImage UIImage nil 在语音通话期间,大视图中背景图像的优先级高于背景颜色
smallViewPostion ZegoViewPosition .topRight 小视图的默认位置
useVideoViewAspectFill Bool false 默认为false,正常黑色边缘模式

测试提示

  1. 您需要使用真设备进行测试,ios模拟器不支持摄像头。
  2. 请注意,在测试时,两个设备不应离得太近,如果您的两个设备距离较近,可能会出现捕捉彼此声音的问题,导致回声震荡。请参阅https://en.wikipedia.org/wiki/Audio_feedback