You can download and install the app we provide to try out the real-time audio/video call feature.
Call | Answer |
---|---|
![]() |
![]() |
Note:To make it easier for you to implement the real-time audio/video call feature, we have refactored the
TUICalling
component. You no longer need to pay attention to UI as it is now implemented within theTUICalling
component.
TestVideoCall
and click Create.Note:This feature uses two basic PaaS services of Tencent Cloud, namely TRTC and IM. When you activate TRTC, IM will be activated automatically. IM is a value-added service. See Pricing for its billing details.
Clone or download the TUICalling source code.
In the Modify Configuration step, select your platform.
Find and open iOS/Example/Debug/GenerateTestUserSig.swift
.
Set the following parameters in GenerateTestUserSig.swift
:
Click Next to complete the creation.
After compilation, click Return to Overview Page.
Note:
- The method for generating
UserSig
described in this document involves configuringSECRETKEY
in client code. In this method,SECRETKEY
may be easily decompiled and reversed, and if your key is disclosed, attackers can steal your Tencent Cloud traffic. Therefore, this method is suitable only for the local execution and debugging of the app.- The correct
UserSig
distribution method is to integrate the calculation code ofUserSig
into your server and provide an application-oriented API. WhenUserSig
is needed, your application can send a request to the business server for a dynamicUserSig
. For more information, see How do I calculate UserSig on the server?.
Open the source code project TUICalling/Example/TUICallingApp.xcworkspace
with Xcode (version 11.0 or above) and click Run.
Note:You need at least two devices to try out the application.
Enter a username (which must be unique) and log in.
Enter the userId
of the person you want to call and tap Search.
Tap Call and select Video Call (Make sure that the callee is active in the application, or the call may fail).
Enter a username (which must be unique) and log in.
Go to the homepage and wait for the incoming call.
In the source code, the Source
folder contains three subfolders: ui
, model
, and Service
. The Service
subfolder includes the open-source TUICallingManager
component, which we share with the public. You can find the component’s APIs in the TUICallingManager.h
file.
You can enable the real-time audio/video call feature for your project with ease using the open-source TUICalling
and TUICallingManager
components, with no need to implement complicated call UI or logic by yourself.
The call component TRTCCalling
depends on the TRTC SDK and IM SDK. You can integrate the two SDKs into your project by following the steps below:
Method 1: adding dependencies via CocoaPods
pod 'TXIMSDK_iOS'
pod 'TXLiteAVSDK_TRTC'
Method 2: adding dependencies through local files
If your access to the CocoaPods repository is slow, you can download the ZIP files of the SDKs and manually integrate them into your project as instructed in the documents below.
SDK | Download Page | Integration Guide |
---|---|---|
TRTC SDK | Download | Integration Documentation |
IM SDK | Download | Integration document |
Configure camera and mic permission requests by adding Privacy - Camera Usage Description
and Privacy - Microphone Usage Description
in info.plist
.
TUICalling
componentTo import the component through CocoaPods, follow the steps below:
Source
, Resources
, and TXAppBasic
folders and the TUICalling.podspec
file under the demo project directory to your project directory.Podfile
and run pod install
to complete the import.pod 'TXAppBasic', :path => "../TXAppBasic/"
pod 'TXLiteAVSDK_TRTC'
pod 'TUICalling', :path => "../", :subspecs => ["TRTC"]
TUICallingManager.sharedInstance()
to initialize the component.TUILogin.initWithSdkAppID(SDKAPPID)
to initialize login.TUILogin.login(userId, userSig)
to log in to the component. Specify the key parameters as described below:Parameter | Description |
---|---|
sdkAppID | You can view `SDKAppID` in the TRTC console. |
userId | ID of the current user, which is a string that can contain letters (a-z and A-Z), digits (0-9), hyphens (-), and underscores (_). We recommend you set it based on your business account system. |
userSig | Tencent Cloud's proprietary security signature. For the calculation method, please see UserSig. |
// Initialize the component
TUICallingManager.sharedInstance();
// Log in to the component
TUILogin.initWithSdkAppID(SDKAPPID)
TUILogin.login(userId, userSig) {
print("login success")
} fail: { code, errorDes in
print("login failed, code:\(code), error: \(errorDes ?? "nil")")
}
call();
of TUICallingManager
to initiate a call, passing in the user IDs (userIDs
) and call type (type
). For the call type, you can pass in .audio
(audio call) or .video
(video call). If only one user ID is passed in for userIDs
, the call is a one-to-one call; if two or more user IDs are passed in, the call is a group call.// 2. Register the listener
TUICallingManager.shareInstance().setCallingListener(listener: TUICallingListerner())
// 2. Set whether to enable custom views (disabled by default)
TUICallingManager.shareInstance().enableCustomViewRoute(enable: true)
// 3. Set callbacks
public func shouldShowOnCallView() -> Bool {
return true;
}
public func callStart(userIDs: [String], type: TUICallingType, role: TUICallingRole, viewController: UIViewController?) { if let vc = viewController {
callingVC = vc;
vc.modalPresentationStyle = .fullScreen
if var topController = UIApplication.shared.keyWindow?.rootViewController {
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
if let navigationVC = topController as? UINavigationController {
if navigationVC.viewControllers.contains(self) {
present(vc, animated: false, completion: nil)
} else {
navigationVC.popToRootViewController(animated: false)
navigationVC.pushViewController(self, animated: false)
navigationVC.present(vc, animated: false, completion: nil)
}
} else {
topController.present(vc, animated: false, completion: nil)
}
}
}
}
public func callEnd(userIDs: [String], type: TUICallingType, role: TUICallingRole, totalTime: Float) {
callingVC.dismiss(animated: true, completion: nil)
}
public func onCallEvent(event: TUICallingEvent, type: TUICallingType, role: TUICallingRole, message: String) {
}
// 4. Make a call
TUICallingManager.shareInstance().call(userIDs, .video)
Note:If your project does not require the offline answering feature, for example, if it offers online customer service, your integration can end at step 5. If your project is a social networking service, we recommend you enable offline answering.
The IM SDK supports offline push, but additional configuration is required to enable the feature.
sendModel
) of TRTCCallingImpl
. After completing the offline push configuration for your application, you will be able to send notifications to offline users.The table below lists the APIs of the TUICalling
component.
API | Description |
---|---|
call | Sends call invitations by user ID. |
receiveAPNSCalled | Answers a call. |
setCallingListener | Sets the listener. |
setCallingBell | Sets the ringtone (preferably shorter than 30s). |
enableMuteMode | Enables/Disables the mute mode. |
enableCustomViewRoute | Enables/Disables custom views. After enabling custom views, you will receive a CallingView instance in the callback for calling/being called, and can decide how to display the view by yourself. The view must be displayed full screen or in proportion to the screen size; otherwise, an error may occur. |
Was this page helpful?