iOS

This document describes how to quickly integrate the TUICallKit component. Performing the following key steps generally takes about an hour, after which you can implement the video call feature with complete UIs.

Environment Preparations

Xcode 13 or later.
iOS 12.0 or later.

Step 1. Activate the service

Before using Tencent Cloud's audio and video services, you need to go to the Console and activate the audio and video service for your application. For specific steps, please refer to Activate the Service.

Step 2. Import the component

Use CocoaPods to import the component as follows:
1. Add the following dependency to your Podfile.
Swift
Objective-C
pod 'TUICallKit_Swift'
pod 'TUICallKit'
2. Run the following command to install the component:
pod install
If the latest version of TUICallKit cannot be installed, run the following command to update the local CocoaPods repository list:
pod repo update
Afterwards, execute the following command to update the Pod version of the component library.
pod update

Step 3. Configure the project

Your app needs mic and camera permissions to implement audio/video communication. Add the two items below to Info.plist of your app. Their content is what users see in the mic and camera access pop-up windows.
<key>NSCameraUsageDescription</key>
<string>CallingApp needs to access your camera to capture video.</string>
<key>NSMicrophoneUsageDescription</key>
<string>CallingApp needs to access your mic to capture audio.</string>

img



Step 4. Log in to the TUICallKit component

Add the following code to your project to call the relevant APIs in TUICore to log in to the TUICallKit component. This step is very important, as the user can use the component features properly only after a successful login. Carefully check whether the relevant parameters are correctly configured:
Swift
Objective-C
import TUICore

TUILogin.login(1400000001, // Replace it with the `SDKAppID` obtained in step 1.
userID: "denny", // Replace it with your `UserID`.
userSig: "xxxxxxxxxxx") { // You can 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")")
}
#import <TUICore/TUILogin.h>

[TUILogin login:1400000001 // Replace it with the `SDKAppID` obtained in step 1.
userID:@"denny" // Replace it with your `UserID`.
userSig:@"xxxxxxxxxxx" // You can calculate a `UserSig` in the console and enter it here.
succ:^{
NSLog(@"login success");
} fail:^(int code, NSString *msg) {
NSLog(@"login failed, code: %d, error: %@", code, msg);
}
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 by clicking the UserSig Generate button 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 TUICallKit component from the server.

Step 5: Setting Nickname and Avatar

If you need to customize your nickname or avatar, you can update them using the following interface:
Swift
Objective-C
TUICallKit.createInstance().setSelfInfo(nickname: "nickname", avatar: "profile photo URL") {

} fail: { code, message in

}
[[TUICallKit createInstance] setSelfInfo:@"nickname" avatar:@"profile photo URL" succ:^{

} fail:^(int code, NSString *errMsg) {

}];
Note:
The update of the callee's nickname and profile photo may be delayed during a call between non-friend users due to the user privacy settings. After a call is made successfully, the information will also be updated properly in subsequent calls.

Step 6: Make your First Phone Call

By calling the call function of TUICallKit and specifying the call type and the callee's userId, you can initiate a voice or video call.
Swift
Objective-C
import TUICallKit

// Initiate a 1-on-1 video call (suppose the `userId` is `mike`)
TUICallKit.createInstance().call(userId: "mike", callMediaType: .video)
#import <TUICallKit/TUICallKit.h>

// Initiate a 1-on-1 video call (suppose the `userId` is `mike`)
[[TUICallKit createInstance] call:@"mike" callMediaType:TUICallMediaTypeVideo];






Caller
Callee

Additional Features

FAQs

1、What should I do if I receive the error message "The package you purchased does not support this ability"?

The error message indicates that your application's audio/video call capability package has expired or is not activated. You can claim or activate the audio/video call capability as instructed in step 1 to continue using TUICallKit.

2、How to purchase official version?

please refer to Purchase Official Version.

Suggestions and Feedback

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