Live Streaming Kit
  • iOS : Swift
  • Android
  • Web
  • Flutter
  • React Native
  • Overview
  • Quick start
    • Quick start
    • Quick start (with cohosting)
  • Custom prebuilt UI

Quick start

Last updated:2022-11-23 11:26

Integrate the SDK

Add ZegoUIKitPrebuiltLiveStreaming as dependencies

  • Open Terminal, navigate to your project's root directory, and run the following to create a podfile:
    pod init
  • Edit the Podfile file to add the basic dependency:
    pod 'ZegoUIKitPrebuiltLiveStreaming'
  • In Terminal, run the following to download all required dependencies and SDK with Cocoapods:
    pod install

Import ZegoUIKitSDK & ZegoUIKitPrebuiltCall to your project

import ZegoUIKitSDK
import ZegoUIKitPrebuiltLiveStreaming
// YourViewController.swift
class MainViewController: UIViewController {
    //Other code...
}

Using the ZegoUIKitPrebuiltLiveStreamingVC in your project

  • Go to ZEGOCLOUD Admin Console, get the appID and appSign of your project.
  • Specify the userID and userName for connecting the Live Streaming Kit service.
  • liveID represents the live streaming you want to start or watch (only supports single-host live streaming for now).
  • userID, userName, and liveID can only contain numbers, letters, and underlines (_).
  • Using the same liveID will enter the same live streaming.

With the same liveID, only one user can enter the live stream as host. Other users need to enter the live stream as the audience.

// YourViewController.swift
class MainViewController: UIViewController {
    // Other code...
    var userID: String = <#UserID#>
    var userName: String = <#UserName#>
    var liveID: String = <#liveID#>

func startLive() {
        let config: ZegoUIKitPrebuiltLiveStreamingConfig = ZegoUIKitPrebuiltLiveStreamingConfig(kPresetRoleHost)
        let liveVC: ZegoUIKitPrebuiltLiveStreamingVC = ZegoUIKitPrebuiltLiveStreamingVC(yourAppID, appSign: yourAppSign, userID: self.userID, userName: self.userName, liveID: self.liveID, config: config)
        liveVC.modalPresentationStyle = .fullScreen
        self.present(liveVC, animated: true, completion: nil)
}

func watchLive() {
      let config: ZegoUIKitPrebuiltLiveStreamingConfig = ZegoUIKitPrebuiltLiveStreamingConfig(kPresetRoleAudience)
      let liveVC: ZegoUIKitPrebuiltLiveStreamingVC = ZegoUIKitPrebuiltLiveStreamingVC(yourAppID, appSign: yourAppSign, userID: self.userID, userName: self.userName, liveID: self.liveID, config: config)
      liveVC.modalPresentationStyle = .fullScreen
      self.present(liveVC, animated: true, completion: nil)
}

}

Then, you can start live streaming by presenting the liveVC.

Configure your project

Open the Info.plist, add the following code inside the dict part:

<key>NSCameraUsageDescription</key>
<string>We require camera access to connect to a call</string>
<key>NSMicrophoneUsageDescription</key>
<string>We require microphone access to connect to a call</string>

/Pics/ZegoUIKit/iOS/add_mic_camera_permissions.png

Run & Test

Now you have finished all the steps!

You can simply click the Run in XCode to run and test your App on your device.

Custom prebuilt UI

Resources