Video Call
  • iOS : Swift
  • Android
  • Web
  • Flutter
  • React Native
  • Electron
  • Unity3D
  • Cocos Creator
  • Windows
  • macOS
  • Linux
  • Overview
  • Develop your app
    • Quick start
    • Enhance basic feature
      • Use Tokens for authentication
      • Config your video based on scenes
      • Check the room connection status
  • Best practices
    • Implement call invitation
    • Implement a live audio room
  • Upgrade using advanced features
    • Advanced features
      • Message signaling
        • Convey extra information using SEI
    • Distincitve features
      • Customize the video and audio
  • Upgrade using Add-on
  • Resources & Reference
    • SDK
    • Sample codes
    • API reference
      • Client APIs
      • Server APIs
    • Debugging
      • Error codes
    • FAQs
    • Key concepts
  • Documentation
  • Video Call
  • Resources & Reference
  • Sample codes
Sample code
Download

1 Sample source code running guide

ZEGOCLOUD no longer classifies environments into production environments and testing environments.

If you create your project in ZEGOCLOUD Admin Console on/before 2021-11-16, refer to the Testing environment deprecation to upgrade the SDK and adjust related codes.

This sample source code supports iOS and macOS platforms. The requirements for the development environment are relatively high.

The source code of this sample uses SwiftUI to build the interface. To learn more about the environment requirements of the ZegoExpress SDK, please refer to Quick Starts-Integration.

1.1 Prepare the environment

Before you attempt to run the sample source code, make sure that the development environment meets the following requirements:

  • Xcode 13.0 or above.
  • iOS devices or simulators with iOS 14.0 or above that support audio and video calling (real devices are recommended).
  • macOS 11.0 or above.
  • The iOS device is connected to the Internet.

1.2 Prerequisites

Go to ZEGOCLOUD Admin Console to create a new project, and get the AppID and AppSign of your project.

The SDK now also supports using Token for authentication, if you want to change your authentication mode, refer to the Guide for upgrading the authentication mode from using the AppSign to Token.

1.3 Sample source code directory structure

The following directory structure is the file structure of the apple_swift subdirectory, and the file paths mentioned below are all relative to this directory.

.
├─ .gitignore
├─ DownloadSDK.sh
├─ README.md
├─ README_zh.md
├─ Shared
│    ├─ Assets.xcassets 
│    ├─ Deps 
│    ├─ Helper 
│    ├─ HomePage  # Home page
│    ├─ KeyCenter.swift # Fill in the AppID and AppSign of the application
│    ├─ SampleCode.xcconfig
│    ├─ SupportingViews 
│    ├─ Topics # The corresponding function module pages on the interface
│    │    ├─ PlayStream      
│    │    ├─ PublishStream    
│    │    ├─ QuickStart       
│    │    ├─ SoundLevel      
│    │    └─ VideoTalk
│    └─ ZegoExpressExampleApp.swift
├─ Tests Shared
│    ├─ TestEngineModule.swift
│    └─ TestRoomModule.swift
├─ Tests iOS
│    ├─ Info.plist
│    └─ Tests_iOS.swift
├─ Tests macOS
│    ├─ Info.plist
│    └─ Tests_macOS.swift
├─ VERSION.txt
├─ ZegoExpressExample.xcodeproj # Swift project files
├─ iOS
│    ├─ Info.plist
│    ├─ Libs # ZegoExpressVideo iOS SDK storage directory
│    ├─ README.md
│    └─ iOS.entitlements
└─ macOS
       ├─ Info.plist
       ├─ Libs # ZegoExpressVideo Mac SDK storage directory
       ├─ README.md
       └─ macOS.entitlements

1.4 Run the sample source code

  1. Open AppStore, search for "Xcode", and download and install it.
  1. Open the ZegoExpressExample.xcodeproj file by using Xcode.

a. Open Xcode and select File > Open... in the upper-left corner.

b. Select the ZegoExpressExample.xcodeproj file in the uncompressed sample source code folder and open it.

  1. Log in to your Apple ID account.

a. Select Xcode > Preference in the upper-left corner of Xcode.

b. After you click the Account tab, click the plus (+) icon in the lower-left corner, select Add an Apple ID, and click Continue.

c. Enter your Apple ID and password to log in.

  1. Modify the developer certificate.

a. In Xcode, click the "ZegoExpressExample" project on the left.

b. Click the Signing & Capabilities tab and select the developer certificate in Team.

The source code in this sample adaptively obtains TeamID as the suffix of the Bundle identifier, and developers do not need to modify it manually.

  1. The downloaded sample source code lacks the AppID and AppSign required for SDK initialization. You need to modify the KeyCenter.swift file in the Shared directory. Please use the AppID and AppSign obtained in the Prerequisites to fill in the information correctly. Otherwise, the sample source code cannot run properly.

  2. Connect the iOS device to the development computer, click Generic iOS Device in the upper-left corner of Xcode, and select the iOS device or simulator.

You can also switch to the Target of macOS and select MyMac to run the macOS sample source code.
  1. Click Build in the upper-left corner of Xcode to compile and run the sample source code.

1.5 Experience real-time audio and video functions

We recommend you run your project on a real device. If your app runs successfully, you should hear the sound and see the video captured locally from your device.

To test out the real-time audio and video features, visit the ZEGO Express Web Demo, and enter the same AppID, Server and RoomID to join the same room. If it runs successfully, you should be able to view the video from both the local side and the remote side, and hear the sound from both sides as well.

In audio-only scenarios, no video will be captured and displayed.

Page Directory