Skip to main content

iOS Core SDK Quickstart

This quickstart shows how to use Dyte's iOS Core SDK to add live video and audio to your iOS applications.

For getting started quickly, you can use our sample code. You can clone and run a sample application from the iOS Core SDK GitHub repository.

Objective

You'll learn how to:

Before Getting Started

Step 1: Install the SDK

  1. Set your platform to iOS 13.0 or above in your Podfile.
platform :ios, '13.0'
  1. Add 'DyteiOSCore' to your Podfile.
pod 'DyteiOSCore' 
  1. Install the client SDK from pod.
pod install
  1. Add the following entries to the info.plist file. This gives permission to your app to access the camera and microphone, access photos, 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 DyteMobileClient 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 DyteiOSClientBuilder().build().
let meeting = DyteiOSClientBuilder().build()
  1. Add the required listeners and implement callback stubs as per requirement
meeting.addMeetingRoomEventsListener(meetingRoomEventsListener: self)
meeting.addParticipantEventsListener(participantEventsListener: self)
meeting.addSelfEventsListener(selfEventsListener: self)
meeting.addParticipantEventsListener(participantEventsListener: self)
meeting.addChatEventsListener(chatEventsListener: self)
meeting.addPollEventsListener(pollEventsListener: self)
meeting.addRecordingEventsListener(recordingEventsListener: self)
meeting.addWaitlistEventListener(waitlistEventListener: self)
meeting.addLiveStreamEventsListener(liveStreamEventsListener: self)

Step 3: Set the properties in the DyteMeetingInfo class

Add authToken that you got from the REST API to constructor of DyteMeetingInfoV2 - 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.
baseUrlBase URL of the dyte's enviorment you have created the meeting on.
let meetingInfo = DyteMeetingInfoV2(authToken: authToken,
enableAudio: true,
enableVideo: true,
baseUrl: "dyte.io")

Step 4: Initialize the connection request

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

meeting.doInit(dyteMeetingInfo_: meetingInfo)

Note: This is the asynchronous method, You will have to attached observer (meeting.addMeetingRoomEventsListener(meetingRoomEventsListener: self) ) to know its completion state, success or failure, Listen to below callbacks of 'DyteMeetingRoomEventsListener'.

func onMeetingInitCompleted() {
}

func onMeetingInitFailed(exception: KotlinException) {
}

OR

meeting.doInit(dyteMeetingInfo: DyteMeetingInfoV2,
onInitCompleted: () -> Void,
onInitFailed_: () -> Void)

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

Step 5: Connect to the meeting

Now, you have established the connection with the Dyte meeting server successfully. Once onMeetingInitCompleted() is triggered, next step is to join the room.

Join the room

To join the meeting room, do the following only after you received the doInit completion callbacks.

func onMeetingInitCompleted() {
meeting.joinRoom()
}

Or

 meeting.doInit(dyteMeetingInfo: meetingInfo) {
self.meeting.joinRoom {
print("Room Joined successfully")
} onRoomJoinFailed: {
print("Room Joined failed")
}
} onInitFailed_: {
print("Meeting Initialisation got failed")
}

Join room event listeners: Once you call joinRoom(), you can listen to callbacks for this action on meeting object if you have done meeting.addSelfEventsListener(selfEventsListener: self).

extension MeetingViewModel: DyteSelfEventsListener {
func onMeetingRoomJoinStarted() {
// meeting join started
}

func onMeetingRoomJoined() {
// meeting room joined successfully
}

func onMeetingRoomJoinFailed(exception: KotlinException) {
// error in joining meeting room.
}
}

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()

Leave room event listeners: You can listen to leaveRoom() callbacks by registering obsever on meeting object as follows:

extension MeetingViewModel: DyteSelfEventsListener {
func onMeetingRoomLeaveStarted() {
// meeting room leave started
}

func onMeetingRoomLeft() {
// meeting room leave completed
}
}