UIView designed specifically for live streaming. It acts as the canvas for your video layout. On the host side, AtomicPusher manages local audio/video capture and streaming. On the audience side, AtomicPlayer handles stream playback. Both components use setView to render video onto the same AtomicLiveView. You only need to focus on building your UI and interaction logic.
pod 'AtomicXCore' to your Podfile and run pod install.target 'xxxx' dopod 'AtomicXCore', '~> 5.3'end
Info.plist.<key>NSCameraUsageDescription</key><string>TUILiveKit requires access to your camera. Video recording will have visuals only after enabling.</string><key>NSMicrophoneUsageDescription</key><string>TUILiveKit requires access to your microphone. Video recording will have audio only after enabling.</string>

LoginStore.shared.login in your project to complete login. This step is required before using any features in AtomicXCore.LoginStore.shared.login only after your app's own user account login is successful. This ensures your login logic remains clear and consistent.import AtomicXCore// AppDelegate.swiftfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {LoginStore.shared.login(sdkAppID: 1400000001, // Replace with your SDKAppIDuserID: "test_001", // Replace with your UserIDuserSig: "xxxxxxxxxxx") { result in // Replace with your UserSigswitch result {case .success(let info):debugPrint("login success")case .failure(let error):debugPrint("login failed code:\\(error.code), message:\\(error.message)")}}return true}
Parameter | Type | Description |
sdkAppId | int | |
userId | string | Unique identifier for the current user. Use only letters, numbers, hyphens, and underscores. Avoid simple IDs like 1, 123, etc., to prevent multi-device login conflicts. |
userSig | string | A ticket for Tencent Cloud authentication. Please note: Development Environment: You can use the local GenerateTestUserSig.genTestSig function to generate a UserSig or generate a temporary UserSig via the UserSig Generation Tool.Production Environment: To prevent key leakage, you must use a server-side method to generate UserSig. For details, see Generating UserSig on the Server. |

AtomicLiveView instance and set viewType to AtomicLiveViewType.pushView.import AtomicXCore// YourAnchorViewController is your host streaming view controllerclass YourAnchorViewController: UIViewController {private let liveId: String// 1. Add AtomicLiveView as a propertyprivate let liveView = AtomicLiveView(viewType:.pushView, frame: UIScreen.main.bounds)// 2. Convenience initializer for liveIdpublic init(liveId: String) {self.liveId = liveIdsuper.init(nibName: nil, bundle: nil)}required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}public override func viewDidLoad() {super.viewDidLoad()// 3. Add the streaming view to the controller's viewview.addSubview(liveView)}}
openLocalCamera and openLocalMicrophone APIs to enable the camera and microphone. AtomicLiveView automatically previews the camera stream. Example:import AtomicXCoreclass YourAnchorViewController: UIViewController {// ... other code ...public override func viewDidLoad() {super.viewDidLoad()// Enable devicesopenDevices()}private func openDevices() {// 1. Enable front cameraDeviceStore.shared.openLocalCamera(isFront: true, completion: nil)// 2. Enable microphoneDeviceStore.shared.openLocalMicrophone(completion: nil)}}
setView, then call startPush to begin streaming.import AtomicXCoreclass YourAnchorViewController: UIViewController {// ... other code ...// Start streamingprivate func startLive() {// 1. Bind rendering view to AtomicPusher for local previewAtomicPusher.shared.setView(liveView)// 2. Configure live room infovar config = PusherInfo()config.liveID = self.liveId // Set live room IDconfig.liveName = "test live" // Set live room name// 3. Start streamingAtomicPusher.shared.startPush(config: config)debugPrint("startPush")}}
PusherInfo Parameter DetailsParameter Name | Type| | Attribute | Description |
liveID | String | Required | Unique identifier for the live room. |
liveName | String | Optional | Title of the live room. |
notice | String | Optional | Announcement for the live room. |
metaData | [String: String] | Optional | Custom metadata for the live room. |
isPublicVisible | Bool | Optional | Whether the room is publicly visible (true: yes, false: no). |
coverURL | String | Optional | Cover image URL for the live room. |
backgroundURL | String | Optional | Cover image URL for the live room. |
categoryList | [NSNumber] | Optional | Background image URL for the live room. |
stopPush to stop streaming. The SDK will handle stopping the stream and destroying the room.import AtomicXCoreclass YourAnchorViewController: UIViewController {// ... other code ...// End streamingprivate func stopLive() {AtomicPusher.shared.stopPush()debugPrint("stopPush")}}

AtomicLiveView instance and set viewType to AtomicLiveViewType.playView.import AtomicXCore// YourAudienceViewController is your audience viewing controllerclass YourAudienceViewController: UIViewController {// 1. Initialize playback pageprivate let liveView = AtomicLiveView(viewType:.playView, frame: UIScreen.main.bounds)private let player = AtomicPlayer()private let liveId: Stringpublic init(liveId: String) {self.liveId = liveIdsuper.init(nibName: nil, bundle: nil)// 2. Bind rendering viewplayer.setView(liveView)}required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}public override func viewDidLoad() {super.viewDidLoad()// 3. Add playback page to your viewview.addSubview(liveView)}}
setView, then call joinChannel to enter the live room. After joining, call startPlay to play the stream.import AtomicXCoreclass YourAudienceViewController: UIViewController {// ... other code ...public override func viewDidLoad() {super.viewDidLoad()// 3. Add playback pageview.addSubview(liveView)// 4. Enter live roomjoinLive()}private func joinLive() {// Enter live room; after success, start playback// - liveId: Same as host's liveIdplayer.joinChannel(liveID: liveId) { [weak self] result inguard let self = self else { return }switch result {case .success:// Playback URL is generated as livekit://liveid=<liveId>player.startPlay(url: "livekit://liveid=\\(liveId)")debugPrint("joinChannel success")case .failure(let error):debugPrint("joinChannel error \\(error.message)")// If joining fails, exit the page// self.dismiss(animated: true)default: break}}}}
stopPlay and leaveChannel to exit. The SDK will stop playback and exit the room.import AtomicXCoreclass YourAudienceViewController: UIViewController {// ... other code ...// Exit live streamprivate func leaveLive() {player.stopPlay()player.leaveChannel()debugPrint("leaveLive success")}}
AtomicPlayer's playerEvent to listen for events.import AtomicXCoreimport Combine // 1. Import Combine frameworkclass YourAudienceViewController: UIViewController {// ... other code (liveView, player, liveId, init, deinit, joinLive, leaveLive, etc.) ...// 2. Define cancellableSet to manage subscriptionsprivate var cancellableSet: Set<AnyCancellable> = []public override func viewDidLoad() {super.viewDidLoad()view.addSubview(liveView)// 3. Listen for live eventssetupLiveEventListener()// 4. Enter live roomjoinLive()}// 5. Set up event listeningprivate func setupLiveEventListener() {player.playerEvent.receive(on: RunLoop.main) // Ensure UI updates are on the main thread.sink { [weak self] event inguard let self = self else { return }switch event {case .liveEnded(let reason):// Live endeddebugPrint("Live ended. reason: \\(reason.rawValue)")// Handle exit logic, e.g., close the page// self.dismiss(animated: true)case .kickedOut(let reason, let message):// Audience kicked outdebugPrint("Kicked out of live. reason: \\(reason.rawValue), message: \\(message)")// Handle exit logic// self.dismiss(animated: true)}}.store(in: &cancellableSet) // Manage subscription}// ... joinLive() and leaveLive() methods ...}
Layout Type | Dynamic Grid Layout | Floating Window Layout | Fixed Grid Layout | Fixed Window Layout |
Template ID | 600 | 601 | 800 | 801 |
Description | Default layout, dynamically adjusts grid size based on the number of co-hosts. | Co-host guests are displayed as floating windows. | Fixed number of co-hosts, each guest occupies a fixed grid. | Fixed number of co-hosts, guests are displayed as fixed windows. |
Run Effect | ![]() | ![]() | ![]() | ![]() |
Live Feature | Feature Introduction | Feature Stores | Implementation Guide |
Audience Audio/Video Co-hosting | Audience can request to take a mic seat and interact with the host in real-time video. | ||
Host Cross-room Co-hosting PK | Hosts from different rooms can connect for interaction or PK. | ||
Add Live Comments Chat | Audience can send and receive real-time text messages in the live room. | ||
Build Gift System | Audience can send virtual gifts to the host, increasing interaction and fun. |
Store/Component | Feature Description | API Documentation |
AtomicPusher | Host streaming: Local audio/video capture and preview, start/stop streaming, live room info update, streaming status/statistics, event callbacks. | |
AtomicPlayer | Audience playback: Render view binding, join/leave channel, start/stop playback, playback status/statistics, event callbacks. | |
LiveListStore | Live room lifecycle management: Create/join/leave/destroy room, query room list, modify live info (name, announcement, etc.), listen for live status (e.g., kicked out, ended). | |
DeviceStore | Audio/video device control: Microphone (switch/volume), camera (switch/swap/quality), screen sharing, real-time device status monitoring. | |
CoGuestStore | Audience co-hosting management: Co-host request/invite/accept/reject, co-host member permission control (microphone/camera), status sync. | |
CoHostStore | Host cross-room co-hosting: Supports multiple layout templates (dynamic grid, etc.), initiate/accept/reject co-hosting, co-host interaction management. | |
BattleStore | Host PK battle: Initiate PK (set duration/opponent), manage PK status (start/end), sync scores, listen for battle results. | |
GiftStore | Gift interaction: Get gift list, send/receive gifts, listen for gift events (including sender, gift details). | |
BarrageStore | Live comments: Send text/custom comments, maintain comment list, real-time comment status monitoring. | |
LikeStore | Like interaction: Send likes, listen for like events, sync total like count. | |
LiveAudienceStore | Audience management: Get real-time audience list (ID/name/avatar), count audience, listen for audience entry/exit events. | |
AudioEffectStore | Audio effects: Voice changer (child/male voice), reverb (KTV, etc.), monitor adjustment, real-time effect switching. | |
BaseBeautyStore | Basic beauty: Adjust smoothing/whitening/rosiness (0-100 levels), reset beauty state, sync effect parameters. |
DeviceStore.shared.openLocalCamera(isFront: true) to enable the camera.AtomicLiveView uses viewType as AtomicLiveViewType.pushView.AtomicLiveView uses viewType as AtomicLiveViewType.playView.rsync(xxxx):1:1: SnapKit.framework/SnapKit_Privacy.bundle/: mkpathat: Operation not permitted
rsync script's write permissions to SnapKit.framework resource files during the build process, causing the SnapKit_Privacy.bundle in the framework to fail to copy properly.User Script Sandboxing (or ENABLE_USER_SCRIPT_SANDBOXING), and change its value from YES to NO.Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários