Skip to main content

Quickstart

This quickstart shows how to use Cloudflare's core SDKs to add live video and audio to your iOS applications.

Objective

You'll learn how to:

Before Getting Started

Make sure you've read the Getting Started with RealtimeKit topic and completed the following steps:

Step 1: Install the SDK

Add RealtimeKit SDK through Swift Package Manager in Xcode. Use https://github.com/dyte-in/RealtimeKitCoreiOS.git as the package source.

Add the following entries to the info.plist file. This gives your app permissions to access the camera and microphone, access photos, and install the required fonts and icons.

<key>NSBluetoothPeripheralUsageDescription</key>
<string>We will use your Bluetooth to access your Bluetooth headphones.</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>We will use your Bluetooth to access your Bluetooth headphones.</string>
<key>NSCameraUsageDescription</key>
<string>For people to see you during meetings, we need access to your camera.</string>
<key>NSMicrophoneUsageDescription</key>
<string>For people to hear you during meetings, we need access to your microphone.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>For people to share, we need access to your photos.</string>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>voip</string>
<string>fetch</string>
<string>remote-notification</string>
</array>

The UIBackgroundModes key is used in the Info.plist file of an iOS app to declare the app's supported background execution modes. This key is an array of strings that specifies the types of background tasks that the app supports. By declaring the background modes, the app can continue to run in the background and perform specific tasks even when it is not in the foreground. It's important to note that the use of background modes should be justified and comply with Apple's App Store Review Guidelines. Apps that misuse background modes or unnecessarily run in the background may be rejected during the app review process.

Sources: Apple Developer Documentation: Declaring Your App's Supported Background Tasks

Step 2: Initialize the SDK

  1. The RealtimeKitClient is the main class of the SDK. It is the main entry point of the SDK. It is the only class that you need to instantiate in order to use the SDK. To instantiate DyteMobileClient, you should use RealtimeKitiOSClientBuilder().build().
let meeting = RealtimeKitiOSClientBuilder().build()
  1. Add the required listeners and implement callback stubs as per requirement
meeting.addMeetingRoomEventsListener(meetingRoomEventsListener: self)
meeting.addParticipantsEventListener(participantEventsListener: self)
meeting.addSelfEventsListener(selfEventsListener: self)
meeting.addChatEventsListener(chatEventsListener: self)
meeting.addPollEventsListener(pollEventsListener: self)
meeting.addRecordingEventsListener(recordingEventsListener: self)
meeting.addWaitlistEventListener(waitlistEventListener: self)
meeting.addLiveStreamEventsListener(liveStreamEventsListener: self)

Step 3: Configure a RealtimeKit meeting

Add authToken that you got from the REST API to constructor of RtkMeetingInfo - Add Participant API

NameDescription
authTokenAfter you've created the meeting, add each participant to the meeting using the Add Participant API The API response contains the authToken.
enableAudioSet whether to join the meeting with your Mic ON or OFF by passing true or false.
enableVideoSet whether to join the meeting with your Camera ON or OFF by passing true or false.
baseDomainBase URL of the dyte's enviorment you have created the meeting on.
let meetingInfo = RtkMeetingInfo(authToken: authToken,
enableAudio: true,
enableVideo: true)

Step 4: Initialize the RealtimeKit meeting

To initialize the connection request, call the doInit() method obtained on meeting with the meetingInfo argument. This will establish the connection with the RealtimeKit meeting server.

meeting.doInit(meetingInfo: meetingInfo, onSuccess: {}, onFailure: {_ in})

To initialize the connection request, call the doInit method which is asynchronous and callback based.

Step 5: Go live with your RealtimeKit meeting!

Join the room

To join the meeting room, call joinRoom() method on the meeting instance as shown below.

meeting.joinRoom(onSuccess: {}, onFailure: {_ in})

Leave the room

Once the meeting is over, you can leave the meeting room. To leave the meeting call leaveRoom() on meeting object.

meeting.leaveRoom(onSuccess: {}, onFailure: {_ in})