Live Room Switching | Live Viewing |
![]() |
![]() |
TUILiveKit trial version or activate the paid version.import AtomicXCoreimport SnapKitimport TUILiveKitimport UIKitclass AudienceLiveListViewController: UIViewController {private let liveListView: LiveListViewprivate let pageSize = 6private var isLoading = falseinit(liveID: String = "") {// 1. Create LiveListView; the passed liveID will be the first live room displayedliveListView = LiveListView(liveID: liveID)super.init(nibName: nil, bundle: nil)}@available(*, unavailable)required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}override func loadView() {// 2. Set LiveListView as the controller's root viewview = liveListView}override func viewDidLoad() {super.viewDidLoad()// 3. Set the load more callback, triggered when the audience swipes near the end of the listliveListView.onLoadMore = { [weak self] inself?.loadMore()}// 4. Fetch the initial live room list and set it to LiveListViewrefresh()}private func refresh() {guard !isLoading else { return }fetch(cursor: "") { [weak self] inself?.liveListView.setData(LiveListStore.shared.state.value.liveList)}}private func loadMore() {guard !isLoading else { return }let cursor = LiveListStore.shared.state.value.liveListCursorguard !cursor.isEmpty else { return }let oldCount = LiveListStore.shared.state.value.liveList.countfetch(cursor: cursor) { [weak self] inlet list = LiveListStore.shared.state.value.liveListguard list.count > oldCount else { return }self?.liveListView.appendData(Array(list[oldCount..<list.count]))}}private func fetch(cursor: String, completion: @escaping () -> Void) {isLoading = trueLiveListStore.shared.fetchLiveList(cursor: cursor, count: pageSize) { [weak self] result inDispatchQueue.main.async {self?.isLoading = falseswitch result {case .success:completion()case .failure(let error):print("fetchLiveList failed:\\(error.localizedDescription)")}}}}}
// Jump to the "Swipe to Switch Live Room" viewing pagelet liveListVC = AudienceLiveListViewController(liveID: "Your live room id")liveListVC.modalPresentationStyle = .fullScreenpresent(liveListVC, animated: false)
Method / Property | Description |
init(liveID: String = "") | Constructor. The liveID is displayed as the first live room (pinned to the top of the list). If not provided, the first item in the list is shown. |
setData(_ list: [LiveInfo]) | Sets the live room list data. LiveIDs are deduplicated internally, and the liveID passed in the constructor is pinned to the top. |
appendData(_ list: [LiveInfo]) | Appends live room data to the end of the list for paginated loading. Existing live rooms are updated, not inserted repeatedly. |
onLoadMore | Closure callback, triggered when the audience swipes to within two live rooms of the end of the list. Use this to load the next page of data. |
Capability | API |
Fetch List | LiveListStore.shared.fetchLiveList(cursor:count:completion:) |
List Data | LiveListStore.shared.state.value.liveList |
Pagination Cursor | LiveListStore.shared.state.value.liveListCursor (empty means no more data) |
Feature | Description | Integration Guide |
Audience Viewing | Use PlayerView to watch a single live room, including stream pulling, Enter Room, and interactive features. | |
Host Streaming | Full host streaming workflow, including pre-stream preparation and post-stream interactions. | |
Gift System | Implement custom gift asset configuration, billing system integration, PK scenario interaction, and more. |
Target → Signing & Capabilities → Background Modes → select Audio, AirPlay, and Picture in Picture. If not declared, iOS will suspend the audio session when the app enters the background.フィードバック