ZEGOCLOUD's easy example is a simple wrapper around our RTC product.

Overview

ZEGOCLOUD easy example

ZEGOCLOUD's easy example is a simple wrapper around our RTC product. You can refer to the sample code for quick integration.

Getting started

Prerequisites

Install Pods

  1. Clone the easy example Github repository.
  2. Open Terminal, navigate to the ZegoEasyExample folder where the Podfile is located, and run the pod repo update command.
  3. Run the pod install command to install all dependencies that are needed.

Modify the project configurations

You need to modify appID and serverSecret to your own account, which can be obtained in the ZEGO Admin Console.

Run the sample code

  1. Connect the iOS device to your computer.

  2. Open Xcode, click the Any iOS Device in the upper left corner, select the iOS device you are using.

  3. Click the Build button in the upper left corner to run the sample code and experience the Live Audio Room service.

Integrate the SDK into your own project

Introduce SDK

1 add ZegoExpressEngine and ZegoToken SDK in your project 2 Run the pod install command to install all dependencies that are needed.

target 'Your_Project_Name' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for ZegoEasyExample
  pod 'ZegoExpressEngine'
  pod ‘ZegoToken’

end

Copy the source code

Copy the AppCenter.swift and ZegoExpressManager.swift files to your project

Method call

The calling sequence of the SDK interface is as follows: createEngine --> joinRoom --> setLocalVideoView/setRemoteVideoView --> leaveRoom

Create engine

Before using the SDK function, you need to create the SDK first. We recommend creating it when the application starts. The sample code is as follows:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // create engine
        ZegoExpressManager.shared.createEngine(appID: AppCenter.appID)
        return true
    }

Join room

When you want to communicate with audio and video, you need to call the join room interface first. According to your business scenario, you can set different audio and video controls through options, such as:

  1. call scene:[.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
  2. Live scene - host: [.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
  3. Live scene - audience:[.autoPlayVideo, .autoPlayAudio]
  4. Chat room - host:[.autoPlayAudio, .publishLocalAudio]
  5. Chat room - audience:[.autoPlayAudio]

The following sample code is an example of a call scenario:

    @IBAction func pressJoinRoom(_ sender: UIButton) {
        
        // join room
        let roomID = "111"
        let user = ZegoUser(userID: "id\(Int(arc4random()))", userName: "Tim")
        let token = generateToken(userID: user.userID)
        let option: ZegoMediaOptions = [.autoPlayVideo, .autoPlayAudio, .publishLocalAudio, .publishLocalVideo]
        ZegoExpressManager.shared.joinRoom(roomID: roomID, user: user, token: token, options: option)
        presentVideoVC()
    }

set video view

If your project needs to use the video communication function, you need to set the View for displaying the video, call setLocalVideoView for the local video, and call setRemoteVideoView for the remote video.

setLocalVideoView:

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        // set video view
        ZegoExpressManager.shared.setLocalVideoView(renderView: localVideoView)
        
    }

setRemoteVideoView:

   func onRoomUserUpdate(udpateType: ZegoUpdateType, userList: [String], roomID: String) {
        for userID in userList {
            // set video view
            ZegoExpressManager.shared.setRemoteVideoView(userID:userID, renderView: remoteVideoView)
        }
    }

leave room

When you want to leave the room, you can call the leaveroom interface.

@IBAction func pressLeaveRoomButton(_ sender: Any) {
    ZegoExpressManager.shared.leaveRoom()
    self.dismiss(animated: true, completion: nil)
}
You might also like...
Example Xcode swift iOS project for Core Data + iCloud syncing
Example Xcode swift iOS project for Core Data + iCloud syncing

iCloudCoreDataStarter Hello, I'm Chad. For the last several months I have been working on Sticker Doodle, an app you should go download right now! In

An example of adding a faux notch using AppKit + SwiftUI
An example of adding a faux notch using AppKit + SwiftUI

faux-notch An example of adding a faux notch using AppKit + SwiftUI What is this? It's a bare-bones example that renders a fake MacBook notch in macOS

A repository of example plugins for Delta Client

Example Plugins for Delta Client This repository contains a few example plugins to help developers get a practical understanding of how to use the plu

CustomPod Example Axon With Swift

CustomPod_Example_Axon Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installa

MVVM example app with RxSwift & RxDataSources & Dependency Injection & UnitTests

Hi there, This is MVVM example app with RxSwift & RxDataSources & Dependency Injection & UnitTests and more 👋 MVVM with RxSwift Example Features: Rea

Todolist-swiftui - An example of using SwiftUI with CoreData

todolist-swiftui An example of using SwiftUI with CoreData Installation Install

SwiftUI + Combine + MVVM - Book search example
SwiftUI + Combine + MVVM - Book search example

CombineBookSearch SwiftUI + Combine + MVVM Example project of SwiftUI and Combine using MVVM architecture pattern.

SwiftUI Todo app example using a React/Redux monolithic state store with flux like dispatch/reduce actions
SwiftUI Todo app example using a React/Redux monolithic state store with flux like dispatch/reduce actions

SwiftUI-Todo-Redux SwiftUI Todo Redux app example using a React/Redux monolithic state store with flux like dispatch/reduce actions Background SwiftUI

ReactorKit karrotFlex example
ReactorKit karrotFlex example

reactorKit-karrotFlex-example 🎉 ReactorKit + KarrotFlex 예제 작성을 위해서 만들어진 프로젝트로 r

Owner
null
Example App for playing around with

BookStore ?? 한글 버전 See new releases and search for programming books from IT Bookstore API This is a sample app to practice using Result type, stubbin

Danny Gilbert 0 Nov 3, 2021
Here there is a simple example using watchOS and SwiftUI

A Simple Demonstration Project using WatchOS + SwiftUI Description This project is a simple demonstration about how to create a WatchOS App using Swif

Leandro Alves da Silva 1 Jul 19, 2022
Demonstration code for a simple Swift property-wrapper, keypath-based dependency injection system. The keypaths ensure compile-time safety for all injectable services.

Injectable Demo Preliminary musings and demonstration code for a simple Swift property-wrapper, keypath-based dependency injection system. The keypath

Michael Long 12 Aug 5, 2022
Advanced Catalyst Example with sidebar, list view, SwiftUI detail view, toolbar & AppKit bundle

Advanced Catalyst Example This is an example of a Catalyst app using a three-column layout, with a primary toolbar. It includes topics such as: Drag &

Steven Troughton-Smith 219 Dec 8, 2022
Example on how to print a NSTableView from your app but then also add text to the print-out.

NSTableView Printing Test This is a demo project so you can check out how printing a table could work. The goal here is to show tabular data on screen

Clean Cocoa 3 Mar 29, 2022
Example for RxFeedback

RxFeedback Sample This is a repository for the RxFeedback code sample. Running Install bazel (This project is tested with Bazel 4.0.0) bazel run //App

Snorlax 4 Oct 8, 2021
An example app with using ShazamKit

ShazamKitExample An example app with using ShazamKit. Check out a live demo on Twitter. Related Resources Introducing ShazamKit WWDC21 — Explore Shaza

Artem Novichkov 10 May 25, 2022
An example project of using the new Character Controller component in RealityKit 2.0

CharacterController in RealityKit 2.0 An example project of using the new Character Controller component in RealityKit 2.0. Demo Tweet Usage Install a

Sai Kambampati 8 Nov 13, 2022
Example project guide you schedules multiple thread for network requests in RxSwift, which is optimize your app's performance better.

RxSwift-Multi-Threading-Example Example project guide you schedules multiple thread for network requests in RxSwift, which is optimize your app's perf

Huy Trinh Duc 6 Nov 4, 2022
This is example project for my presentation in iOSDC JAPAN 2021

Swift PM Project Example This is example project for my presentation in iOSDC JAPAN 2021. Package.swift based project management Multi Modules Multi P

Daiki Matsudate 28 Nov 11, 2022