This tutorial mainly introduces how to implement a basic audio and video call with Objective-C.
Prerequisites
Xcode 13.0 or later.
iPhone or iPad with iOS 9.0 or later.
A valid developer signature for your project.
Integration guideline
Step 1. Import TRTC SDK
Cocoapods Integration
Swift Package Manager Integration
1. Run the following command in a terminal window to install CocoaPods. If you have installed CocoaPods, skip this step.
sudo gem install cocoapods
2. In the terminal window, go to the project root directory and run the following command to create the Podfile for your project.
pod init
3. Edit and save the Podfile as follows.
platform:ios,'8.0'
# Modify the 'App' to the name of your project
target 'App'do
pod 'TXLiteAVSDK_TRTC',:podspec=>'https://liteav.sdk.qcloud.com/pod/liteavsdkspec/TXLiteAVSDK_TRTC.podspec'
end
4. In the terminal window, run the following command to update the local library files and download the TRTC SDK.
pod install
Note:
After the pod install executed, a new .xcworkspace project file is generated. Double-click the .xcworkspace file to open it.
1. Using Xcode 26.4.1 as an example, open the File menu and select Add Package Dependencies.... Paste the following URL into the search field, wait for the results to load, and then click Add Package.
// Version 13.3and later
git@github.com:Tencent-RTC/TRTC_SwiftPM.git
2. At the Choose Package Options step, select the SDK version you wish to integrate. For additional configuration details, refer to Apple's official documentation.
Note:
Swift Package Manager integration is available starting with version 13.3. For earlier versions, use Cocoapods to integrate the SDK.
Step 2. Configure project
1. Once the .xcworkspace file opened, click on the Project Navigator on the left in the Xcode navigation bar, click on your project name, and make sure you select the correct TARGETS in the edit area.
2. In the Build Settings TAB, search for User Script Sandboxing and set its value to No, which could allow the user script access to a wider range of system resources and files.
3. In the Info.plist TAB, add the Privacy-Microphone Usage Description and Privacy-Microphone Usage Description, and fill in the target prompt words used by the Microphone/Camera to obtain the permission to use the microphone and camera.
4. In the Signing & Capabilities TAB, add the Background Modes and check Audio, AirPlay and Picture in Picture to allow the app to run audio, AirPlay and picture-in-picture functions in the background.
2. Declare the TRTCCloud property and the TRTCCloudDelegate interface in the AppDelegate.h file.
@interface AppDelegate : UIResponder <UIApplicationDelegate, TRTCCloudDelegate>// Declare the TRTCCloudDelegate interface
@property(nonatomic, strong) TRTCCloud *trtcCloud;// Declare the TRTCCloud property
3. After entering the AppDelegate.m file, call sharedInstance to create the TRTC instance in the didFinishLaunchingWithOptions method and set up the event listener.
// Recommend to display OnError information via 'toastTip:'
}
Step 5. Turn on/off Camera
1. Declare the UIWindow and UIView properties in the ViewController.h file.
@property(strong, nonatomic) UIWindow *window;// Declare the UIWindow property
@property(nonatomic, strong) UIView *localCameraVideoView;// Declare the UIView property
2. Set the render parameter setLocalRenderParams for the local preview, and call startLocalPreview for the local preview, and start the push after successfully calling enterRoom.
1. Listen to onUserVideoAvailable before entering the room. When you receive the onUserVideoAvailable(userId, true) notification, it means that there are video frames available to play in the road screen.
2. Call startRemoteView to play the video content collected by the remote side.