Live Streaming Kit
  • iOS : Swift
  • Android
  • Web
  • Flutter
  • React Native
  • Overview
  • Quick start
    • Quick start
    • Quick start (with cohosting)
  • Enhance the livestream
    • PK battles
    • Send virtual gifts
  • Customize the livestream
    • Hide components
    • Set a leave confirmation dialog
    • Add custom UI components
    • Modify User Interface text
    • Customize the menu bar
    • Implement an audio-only live
    • Forcefully end a livestream room
  • API Reference
    • API
    • Event
  • Documentation
  • Live Streaming Kit
  • Quick start
  • Quick start

Quick start

Last updated:2023-06-15 18:32

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 ZegoUIKit & ZegoUIKitPrebuiltCall to your project

import ZegoUIKit
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.host()
        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.audience()
      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.

Resources

Page Directory