Skip to main content

iOS SDK (Objective-C)

TgoRTC iOS (Objective-C) SDK for real-time audio/video communication based on LiveKit. The SDK provides Objective-C compatible interfaces through a Swift Bridge.

Installation and Configuration

1. Add SPM Dependency

  1. In Xcode, select File → Add Packages....
  2. Enter the following repository URL:
    https://github.com/TgoRTC/TgoRTCiOS
  3. Under Dependency Rule, select Branch: main.
  4. Click Add Package and check the TgoRTCSDK library.

2. Create Swift Bridging Header (Optional)

Since the SDK is written in Swift, Objective-C projects typically require a bridging header.

  1. Create a new Swift file in your project (e.g., TgoBridge.swift).
  2. When Xcode asks if you want to create a Bridging Header, click Create Bridging Header.
  3. In your Objective-C files where you want to use the SDK, import the generated header:
    #import "YourProjectName-Swift.h"

3. Build Settings Configuration

Ensure the following settings are correctly configured:

  • Defines Module: Yes
  • Swift Language Version: Swift 5 or higher

Quick Start

1. Initialize SDK

TgoOptionsObjC *options = [[TgoOptionsObjC alloc] init];
options.isDebug = YES;
options.mirror = NO;

[[TgoRTCBridge shared] configureWithO:options];

2. Create Room Info and Join

TgoRoomInfoObjC *roomInfo = [[TgoRoomInfoObjC alloc] init];
roomInfo.roomName = @"room-name";
roomInfo.token = @"your-token";
roomInfo.url = @"wss://your-server";
roomInfo.loginUID = @"local-user-id";
roomInfo.rtcType = TgoRTCTypeObjCVideo;

// Join room
[[TgoRTCBridge shared].room joinWithRoomInfo:roomInfo
micEnabled:YES
cameraEnabled:YES
completion:^(BOOL success) {
if (success) {
NSLog(@"Successfully joined room");
}
}];

3. Listen to Connection Status (Delegate)

// Set delegate
[TgoRTCBridge shared].room.delegate = self;

// Implement delegate methods
- (void)room:(NSString *)roomName didChangeStatus:(TgoConnectStatusObjC)status {
switch (status) {
case TgoConnectStatusObjCConnected:
NSLog(@"Connected to room: %@", roomName);
break;
case TgoConnectStatusObjCDisconnected:
NSLog(@"Disconnected from room");
break;
case TgoConnectStatusObjCConnecting:
NSLog(@"Connecting...");
break;
}
}

4. Get Participants

// Get local participant
TgoParticipantBridge *local = [[TgoRTCBridge shared] getLocalParticipant];

// Get all remote participants
NSArray<TgoParticipantBridge *> *remotes = [[TgoRTCBridge shared] getRemoteParticipantsWithIncludeTimeout:NO];

// Listen for new participants (via global delegate)
[TgoRTCBridge shared].participantDelegate = self;

- (void)participantDidJoin:(TgoParticipantBridge *)participant {
NSLog(@"New participant joined: %@", participant.uid);
}

5. Media Control and Events

TgoParticipantBridge *local = [[TgoRTCBridge shared] getLocalParticipant];

// ========== Media Control (Local Only) ==========

// Enable/disable microphone
[local setMicrophoneEnabled:YES completion:nil];

// Enable/disable camera
[local setCameraEnabled:YES completion:nil];

// Switch front/back camera
[local switchCamera];

// ========== Event Listening (Delegate) ==========

local.delegate = self;

- (void)participant:(TgoParticipantBridge *)participant didUpdateMicrophoneOn:(BOOL)isOn {
NSLog(@"User %@ microphone: %@", participant.uid, isOn ? @"on" : @"off");
}

- (void)participant:(TgoParticipantBridge *)participant didUpdateSpeaking:(BOOL)isSpeaking {
NSLog(@"User %@ is speaking: %@", participant.uid, isSpeaking ? @"yes" : @"no");
}

6. Render Video Track (UIKit)

In Objective-C, it is recommended to use TgoVideoView (based on UIKit) for rendering.

// 1. Create video view
self.videoView = [[TgoVideoView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
[self.view addSubview:self.videoView];

// 2. Attach participant's video to the view
TgoParticipantBridge *participant = ...;
[participant attachCameraTo:self.videoView];

// 3. Configure view
[self.videoView setLayoutMode:TgoVideoLayoutModeFill];
[self.videoView setMirrorMode:TgoVideoMirrorModeMirror]; // Recommend mirroring local video

7. Audio Management

// Toggle speakerphone/receiver
[[TgoRTCBridge shared].audio toggleSpeakerphoneWithCompletion:nil];

// Get output device list
[[TgoRTCBridge shared].audio getAudioOutputDevicesWithCompletion:^(NSArray<TgoAudioOutputDeviceObjC *> *devices) {
for (TgoAudioOutputDeviceObjC *device in devices) {
NSLog(@"Found audio device: %@ (type: %@)", device.name, device.typeString);
}
}];

8. Leave Room

[[TgoRTCBridge shared].room leaveRoomWithCompletion:^{
NSLog(@"Left room");
}];

API Reference

TgoRTCBridge (Objective-C Entry Point)

PropertyTypeDescription
sharedTgoRTCBridgeSingleton instance
roomTgoRoomBridgeRoom management
audioTgoAudioBridgeAudio management
participantDelegateid<TgoParticipantDelegateObjC>Global participant event delegate

TgoParticipantBridge

PropertyTypeDescription
uidNSString *Unique User ID
isMicrophoneOnBOOLMicrophone status
isCameraOnBOOLCamera status
isSpeakingBOOLWhether currently speaking
isJoinedBOOLWhether already joined
videoInfoTgoVideoInfoObjC *Video stream info (resolution/bitrate)

Platform Configuration

Permissions (Info.plist)

<key>NSCameraUsageDescription</key>
<string>Need camera access for video calls</string>
<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for audio calls</string>