Guides

Native Integration

System Requirements

  • iOS 13.0 or later
  • Xcode 11.0 or later
  • Swift 5 or later

Installing the Native Player

CocoaPods

SauceLive_iOS can be installed via CocoaPods.To install it, add the following line to your Podfile.

pod 'SauceLiveKit', '~> 1.0.0'

Swift Package Manager

SauceLive_iOS can also be installed via Swift Package Manager.
Open your project in Xcode and go to File > Swift Packages > Add Package Dependency...
Then, enter the repository URL.

dependencies: [
    .package(url: "https://github.com/yourcompany/SauceLiveKit.git", from: "1.0.0")
]

After that, select the desired version of the SDK and add it to your project.

Native Player Initialization

❗️

This code must be added **before anything else.

Import SauceLiveKit in AppDelegate and call the initialization function.

ParameterTypeDescription
apiHostenumAPI host environment configuration
partnerIdStringpartnerId is required to use the player
import UIKit
import SauceLiveKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // SauceLiveKit Initialization (.stage is the default value,  but you can change it to `.prod` or `.dev` as needed.)
        SauceLivePlayerClient.initInstance(partnerID: "Partner ID", apiHost: .stage)
        return true
    }
}

Using the Native Player

SauceLivePlayerClient.getInstance() : BaseView

  • The object required to play the live player and configure the UI

Call this method wherever the player is needed

import SauceLiveKit

class PlayerViewController: UIViewController {
    private var baseView: BaseView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupPlayer()
    }
    
    private func setupPlayer() {
        // Create a player instance using broadcast ID and user token
        // Format of broadcastID: "partnerID-broadcastID"
        let broadcastID = "partner123-broadcast456"
        let userToken = "userAuthToken" // Optional, can be nil
        
        // Create the player view
        baseView = SauceLivePlayerClient.getInstance(
            broadcastID: broadcastID,
            token: userToken,
            viewController: self
        )
        
        //  Start the player
        baseView?.startPlayer()
        
        //  Set up event callbacks
        setupCallbacks()
    }
}

Generate Token Guide

Register event callbacks

private func setupCallbacks() {
    // Callback for broadcast info updates
    baseView?.onBroadcastInfoUpdate = { [weak self] broadcastInfo in
        print("Broadcast title: \(broadcastInfo.title)")
        print("Current viewer coun: \(broadcastInfo.viewCount)")
    }
    
    // Callback for error events
    baseView?.onError = { [weak self] error in
        print("Error occurred: \(error.localizedDescription)")
    }
    
    // Callback for close button tap
    baseView?.onClose = { [weak self] in
        self?.dismiss(animated: true)
    }
    
     // Callback for login button tap
    baseView?.onLogin = { [weak self] in
        // Navigate to the login screen
        self?.presentLoginScreen()
    }
    
    // Callback for coupon click event
    baseView?.onCouponEvent = { [weak self] urlString in
        if let urlString = urlString, let url = URL(string: urlString) {
            UIApplication.shared.open(url)
        }
    }
}

Player UI Configuration

📘

The player UI can be configured via the config settings.

Player Playback

SauceLivePlayerClient.getInstance(broadcastID: String, token: String?, viewController: self)

  • Live player playback
SauceLivePlayerClient.getInstance(
            broadcastID: broadcastID,
            token: userToken,
            viewController: self
        )
ParamsTypeDescription
viewControllerUIViewController
broadcastIdStringLive ID or VOD ID
tokenString?user Token, Use only if member authentication is required