LiveStreamCore
dependency to your Podfile file. If you encounter any issues, you can refer to the example project.target 'xxxx' do......pod 'LiveStreamCore'end
Podfile
file, first use the terminal to cd to the xxxx.xcodeproj
directory and then create the file with the following command.pod init
cd
to the Podfile
directory, and then run the following command to install the component.pod install
pod repo update
pod update
//// AppDelegate.swift//import TUICorefunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {TUILogin.login(1400000001, // Replace it with the SDKAppID obtained in Step 1userID: "denny", // Replace with your UserIDuserSig: "xxxxxxxxxxx") { // Calculate a UserSig in the console and enter it hereprint("login success")} fail: { (code, message) inprint("login failed, code: \\(code), error: \\(message ?? "nil")")}return true}
login
function are as detailed below:Parameter | Type | Description |
SDKAppID | int | Obtained in the last step in Step 1 and not detailed here. |
UserID | String | The ID of the current user, which is a string that can contain only letters (a–z and A–Z), digits (0–9), hyphens (-), or underscores (_). |
userSig | String | The authentication credential used by Tencent Cloud to verify whether the current user is allowed to use the TRTC service. You can get it by using the SDKSecretKey to encrypt the information such as SDKAppID and UserID . You can generate a temporary UserSig on the UserSig Tools page in the console. |
GenerateTestUserSig.genTestSig
function to generate userSig. In this method, the SDKSecretKey is vulnerable to decompilation and reverse engineering, and once your key is leaked, attackers can steal your Tencent Cloud traffic.import LiveStreamCorelet livecoreView = LiveCoreView()
livecoreView.startCamera(useFrontCamera: true) {} onError: { code, message in}
let roomInfo = TUIRoomInfo()roomInfo.roomId = "123456"livecoreView.startLiveStream(roomInfo: roomInfo) { roomInfo in} onError: { code, message in}livecoreView.startMicrophone {} onError: { code, message in}
livecoreView.joinLiveStream(roomId: "roomId_123456") { roomInfo in} onError: { code, message in}
Anchor starts the live streaming room and begins the live stream | Audience joins the live streaming room to watch the live stream |
|
|
// Set grid layoutlivecoreView.setLayoutMode(layoutMode: .gridLayout)// Set floating window layoutlivecoreView.setLayoutMode(layoutMode: .floatLayout)// Set custom layoutlet layoutJson = ""livecoreView.setLayoutMode(layoutMode: .freeLayout, layoutJson: layoutJson)
Anchor Connection - Nine-grid Layout | Anchor Connection - Floating Window Layout | Anchor Connection - Custom Layout |
| |
|
{"1": { // Number of video views"backgroundColor": "#000000", // Background color of the canvas in RGB hexadecimal format"viewInfoList": [{ // Layout information and background color of each video view"x": 0, // Horizontal offset as a proportion of screen width, range [0, 1]"y": 0, // Vertical offset as a proportion of screen width, range [0, 1]"width": 1, // Width of the video view as a proportion of screen width, range [0, 1]"height": -1, // Height of the video view as a proportion of screen width, range [0, 1] or -1; -1 means the view height is the same as the screen height"zOrder": 0, // Z-order of the video view, higher values mean the view is on top"backgroundColor": "#000000" // Background color of the current video view in RGB hexadecimal format}]}}
Was this page helpful?