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:
- Install the Dyte SDK
- Initialize the SDK
- Configure a Dyte meeting
- Initialize the Dyte meeting
- Go live with your Dyte meeting!
Before Getting Started
- Make sure you've read the
Getting Started with Dyte topic and
completed the steps in the
Integrate Dyte section.
You must complete the following steps:
- Create a Dyte Developer Account
- Create a Dyte Meeting
- Add Participant to the meeting
- Install Xcode
- Ensure that Rosetta is installed with Xcode on Mac computers with Apple silicon.
- Make sure your Mac computers are running macOS version 12.0 Monterey or higher.
Step 1: Install the SDK
CocoaPods
- Set your platform to iOS 13.0 or above in your Podfile.
platform :ios, '13.0'
- Add 'DyteiOSCore' to your Podfile.
pod 'DyteiOSCore'
- Install the client SDK from pod.
pod install
Swift Package Manager
AddDyteiOSCore
SDK through Swift Package Manager in Xcode. Use https://github.com/dyte-in/DyteMobileCoreiOS.git as the package source.
- 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
- 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 useDyteiOSClientBuilder().build()
.
let meeting = DyteiOSClientBuilder().build()
- 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
Name | Description |
---|---|
authToken | Token from Add Participant API (The presetName created earlier must be passed in the body of the Add Participant API request) The API response contains the authToken . |
let meetingInfo = DyteMeetingInfoV2(authToken: authToken,
enableAudio: true,
enableVideo: true,
baseUrl: "https://api.dyte.io/v2")
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
To initialize the connection request, call the doInit(dyteMeetingInfo: DyteMeetingInfoV2, onInitCompleted: () -> Void, onInitFailed_: () -> Void)
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
}
}