tencent cloud

Feedback

Last updated: 2024-03-18 15:06:32
    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

    TUICallKit is an audio & video communication component built upon Tencent Cloud's paid PaaS services, Chat and Real-time Communication (TRTC) . In order for you to better experience the Call feature, we offer a 7-day free trial version for each SDKAppID (Note: no additional call duration is provided with the free trial version). Each SDKAppID can apply the free trial version twice, with each trial lasting for 7 days; at the same time, the total number of trial opportunities for all SDKAppID under one account (UIN) is 10.
    You can activate the Call free trial version in the Chat console, with the specific operation steps as follows:
    1. Log into the Chat console, select the data center, and create a new application. Skip this step if you already have an application.
    2. Click on the target application card to enter the application's basic configuration page.
    3. Locate the Call card, and click on "Free Trial".
    4. After confirming the content in the popup window, click on "Activate now". Once activated, you can proceed with integration according to this document.
    5. If you need to purchase the official version for your business to go live, you can proceed to the console to make the purchase. Please refer to Purchase Official Version.

    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. Make a call

    One-to-one video call

    You can call the call function of TUICallKit and specify the call type and the callee's userId to make an audio/video call.
    Swift
    Objective-C
    import TUICallKit
    
    // Make a one-to-one video call. Suppose the `userId` is `mike`.
    TUICallKit.createInstance().call(userId: "mike", callMediaType: .video)
    #import <TUICallKit/TUICallKit.h>
    
    // Make a one-to-one video call. Suppose the `userId` is `mike`.
    [[TUICallKit createInstance] call:@"mike" callMediaType:TUICallMediaTypeVideo];
    Parameter
    Type
    Description
    userId
    String
    The ID of the target user, such as "mike".
    callMediaType
    TUICallMediaType
    The call media type, such as TUICallMediaTypeVideo.

    Group video call

    You can call the groupCall function of TUICallKit and specify the call type and the list of callees' UserID values to make a group audio/video call.
    Swift
    Objective-C
    import TUICallKit
    
    TUICallKit.createInstance().groupCall(groupId: "12345678",
    userIdList: ["denny", "mike", "tommy"],
    callMediaType: .video)
    #import <TUICallKit/TUICallKit.h>
    
    [[TUICallKit createInstance] groupCall:@"12345678"
    userIdList:@[@"denny", @"mike", @"tommy"]
    callMediaType:TUICallMediaTypeVideo];
    Parameter
    Type
    Description
    groupId
    String
    The group ID, such as "12345678".
    userIdList
    Array
    The list of userId values of the target users, such as ["denny", "mike", "tommy"]
    callMediaType
    TUICallMediaType
    The call media type, such as TUICallMediaTypeVideo.
    Note
    You can create a group as instructed in Android, iOS, and macOS. You can also use Chat TUIKit to integrate chat and call scenarios at one stop.
    TUICallKit currently doesn't support making a group video call among users not in a group. If you have such a need, please contact info_rtc@tencent.com.

    Step 6. Answer a call

    After step 4, when receiving an incoming call, the TUICallKit component will automatically display the call answering UI.

    Step 7. Implement more features

    1. Nickname and profile photo settings

    To customize the nickname or profile photo, use the following API for update:
    Swift
    Objective-C
    TUICallKit.createInstance().setSelfInfo(nickname: "nickname", avatar: "avatar url") {
    
    } fail: { code, message in
    
    }
    [[TUICallKit createInstance] setSelfInfo:@"nickname" avatar:@"avatar url" succ:^{
    
    } fail:^(int code, NSString *errMsg) {
    
    }];
    Caution
    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.

    2. Offline call push

    You can make/answer audio or video calls after completing the above steps. However, if you want your users to be able to receive call invitations even when your application is in the background or after it is closed, then you need to also implement the offline call push feature. For more information, see Offline Call Push (iOS).

    3. Floating window

    To implement the floating window feature in your application, call the following API when initializing the TUICallKit component:
    Swift
    Objective-C
    TUICallKit.createInstance().enableFloatWindow(true)
    [[TUICallKit createInstance] enableFloatWindow:YES];

    4. Listening on the call status

    To listen on the call status (for example, the start or end of a call or the call quality during a call), listen on the following events:
    Swift
    Objective-C
    import TUICallEngine
    
    TUICallEngine.createInstance().addObserver(self)
    
    public func onCallBegin(roomId: TUIRoomId, callMediaType: TUICallMediaType, callRole: TUICallRole) {
    
    }
    public func onCallEnd(roomId: TUIRoomId, callMediaType: TUICallMediaType, callRole: TUICallRole, totalTime: Float) {
    
    }
    public func onUserNetworkQualityChanged(networkQualityList: [TUINetworkQualityInfo]) {
    
    }
    #import <TUICallEngine/TUICallEngine.h>
    
    [[TUICallEngine createInstance] addObserver:self];
    
    - (void)onCallBegin:(TUIRoomId *)roomId callMediaType:(TUICallMediaType)callMediaType callRole:(TUICallRole)callRole {
    
    }
    - (void)onCallEnd:(TUIRoomId *)roomId callMediaType:(TUICallMediaType)callMediaType callRole:(TUICallRole)callRole totalTime:(float)totalTime {
    
    }
    - (void)onUserNetworkQualityChanged:(NSArray<TUINetworkQualityInfo *> *)networkQualityList {
    
    }

    5. Custom ringtone

    You can use the following API to customize the ringtone:
    Swift
    Objective-C
    TUICallKit.createInstance().setCallingBell(filePath: " ")
    [[TUICallKit createInstance] setCallingBell:@" "];

    6. Custom call timeout period

    You can set callParams when invoke call, groupCall,inviteUser to change your call timeout period.
    Swift
    Objective-C
    let callParams = TUICallParams()
    let offlinePushInfo = TUIOfflinePushInfo()
    callParams.offlinePushInfo = offlinePushInfo
    callParams.timeout = 30
    callParams.userData = "user data"
    TUICallKit.createInstance().call(userId: "mike", callMediaType: .video, params: callParams) {
    
    } fail: { code, message in
    
    }
    TUICallParams *callParams = [TUICallParams new];
    callParams.offlinePushInfo = [TUIOfflinePushInfo new];
    callParams.timeout = 30;
    callParams.userData = @"user data";
    [[TUICallKit createInstance] call:@"mike"
    callMediaType:TUICallMediaTypeVideo
    params:callParams
    succ:^{
    } fail:^(int code, NSString * _Nullable errMsg) {
    
    }];

    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.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support