提交工单
咨询集成、功能及报价等问题
podfile: pod init
Podfile file to add the basic dependency:pod 'ZegoUIKitPrebuiltLiveStreaming'
pod install
import ZegoUIKit
import ZegoUIKitPrebuiltLiveStreaming
// YourViewController.swift
class MainViewController: UIViewController {
//Other code...
}
appID and appSign of your project.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 (_). 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.
Open the Info.plist, add the following code inside the dict part:
<key>NSCameraUsageDescription</key>
<string>We require camera access to connect to a live</string>
<key>NSMicrophoneUsageDescription</key>
<string>We require microphone access to connect to a live</string>
)
Now you have finished all the steps!
You can simply click the Run in XCode to run and test your App on your device.
