이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

비디오 라이브 통합

This article will guide you through the process of quickly integrating the TUILiveKit component. Performing the following steps generally takes about an hour, after which you can implement live streaming features with a complete UI interface.

Environment Preparations

Xcode 15 or later.
iOS 13.0 or later.
If you have any questions during environment configuration or compilation and running, please refer to the FAQ.

Step 1. Activate the service

Before using audio and video services provided by Tencent Cloud, you need to go to the console and activate the service for your application. For detailed steps, refer to Activate the service.

Step 2. Import the component

Use CocoaPods to import the components as follows:
1. Add the pod 'TUILiveKit'dependency to your Podfile file. If you encounter any issues, you can refer to the example project.
target 'xxxx' do
...
...
pod 'TUILiveKit'
end
If you don't have a Podfile file, first use the terminal to cd to the xxxx.xcodeproj directory and then create the file with the following command.
pod init
2. In the terminal, first cd to the Podfile directory, and then run the following command to install the component.
pod install
If you are unable to install the latest version of TUILiveKit, first delete Podfile.lock and Pods. Then, update the CocoaPods repository list locally by executing the following command.
pod repo update
Afterwards, execute the following command to update the Pod version of the component library.
pod update
3. Compile and run the project. If you encounter any issues, refer to the FAQ. If the problem still can't be solved, you can try running our example project first. We also welcome any feedback on issues you encounter during the integration process.

Step 3. Configure the project

Your app needs to request microphone and camera permissions to use audio/video features. Add the following two items in the App's Info file, which correspond to the prompt messages shown to users when requesting microphone and camera permissions.
<key>NSCameraUsageDescription</key>
<string>TUILiveKit needs to access your camera to capture video.</string>
<key>NSMicrophoneUsageDescription</key>
<string>TUILiveKit needs to access your mic to capture audio.</string>




Step 4. Log in

To log in to the TUICallKit component, add the following code to your project to call the relevant APIs in TUICore. This step is very important, as the user can use the component features properly only after successfully logging in. Carefully check that the relevant parameters are correctly configured:
Swift
Objective-C
//
// AppDelegate.swift
//

import TUICore
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
TUILogin.login(1400000001, // Replace it with the SDKAppID obtained in Step 1
userID: "denny", // Replace with your UserID
userSig: "xxxxxxxxxxx") { // Calculate a UserSig in the console and enter it here
print("login success")
} fail: { (code, message) in
print("login failed, code: \(code), error: \(message ?? "nil")")
}
return true
}
//
// AppDelegate.m
//

#import <TUICore/TUILogin.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[TUILogin login:1400000001 // Replace it with the SDKAppID obtained in Step 1
userID:@"denny" // Please replace it with your UserID
userSig:@"xxxxxxxxxxx" // You can calculate a UserSig in the console and fill it in
print("login success")
succ:^{
NSLog(@"login success");
} fail:^(int code, NSString * _Nullable msg) {
NSLog(@"login failed, code: %d, error: %@", code, msg);
}];
return YES;
}
Parameter description: The key parameters used by the login function are as detailed below:
SDKAppID: Obtained in the last step in Step 1 and not detailed here.
UserID: 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: 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.



For more information, see UserSig.
Note:
Many developers have contacted us with many questions regarding this step. Below are some of the frequently encountered problems:
SDKAppID is invalid.
userSig is set to the value of Secretkey mistakenly. The userSig is generated by using the SecretKey for the purpose of encrypting information such as sdkAppId, userId, and the expiration time. But the value of the userSig that is required cannot be directly substituted with the value of the SecretKey.
userId is set to a simple string such as 1, 123, or 111, and your colleague may be using the same userId while working on a project simultaneously. In this case, login will fail as TRTC doesn't support login on multiple terminals with the same UserID. Therefore, we recommend you use some distinguishable userId values during debugging.
The sample code on GitHub uses the genTestUserSig function to calculate UserSig locally, so as to help you complete the current integration process more quickly. However, this scheme exposes your SecretKey in the application code, which makes it difficult for you to upgrade and protect your SecretKey subsequently. Therefore, we strongly recommend you run the UserSig calculation logic on the server and make the application request the UserSig calculated in real time every time the application uses the TUILiveKit component from the server.

Step 5. Start live streaming

After the above log in to method call returns successfully, call the VideoLiveKit's startLive method, specifying the room ID to start your live streaming page.
Swift
Objective-C
import TUILiveKit

VideoLiveKit.createInstance().startLive(roomId: "your room id")
#import <TUILiveKit/TUILiveKit-Swift.h>

[[VideoLiveKit createInstance] startLiveWithRoomId:@"your room id"];



Video Live Preview Screen



Live video streaming with pictures

Step 6. Watch the live stream

After the above log in to method call returns successfully, call the VideoLiveKit's joinLive method, specifying the room ID to start your live streaming page.
Swift
Objective-C
import UIKit
import TUILiveKit

VideoLiveKit.createInstance().joinLive(roomId: "your room id")
#import <TUILiveKit/TUILiveKit-Swift.h>

[[VideoLiveKit createInstance] joinLiveWithRoomId:@"your room id"];



Video Live Room



Video Live Room

More features

Room List

FAQ

If you encounter problems with access and use, please refer to FAQs.

Suggestions and Feedback

If you have any suggestions or feedback, please contact info_rtc@tencent.com.