Live SDKs iOS v1
Live SDKs iOS
Live SDKs
iOS
Version 1

Start your first live

Copy link

Sendbird Live SDK for iOS offers a variety of functionalities for hosting and watching live events. As a live event's host, a user can create, share their media stream, and use the chat to communicate with other users watching the live event. Users can enter a live event as participants to watch the live event and use the chat to communicate with the live event's host as well as other users.


Requirements

Copy link

The minimum requirements for the Live for Android are:

  • macOS
  • Xcode 15.0 and later
  • A device running iOS 12.0 and later
  • Swift 5.0 and later

Before you start

Copy link

Sendbird Live SDK provides live streaming feature and uses open channels from Sendbird Chat SDK for chat. Installing Sendbird Live SDK will automatically install the Chat SDK as well.

Before installing the Live SDK, create a Sendbird account to acquire an application ID which you will need to initialize the Live SDK. Go to Sendbird Dashboard and create an application by selecting Calls+Live in product type. Once you've created an application, go to Overview and you will see the Application ID.


Get started

Copy link

You can start building your a live event by installing the Live SDK first.

Step 1 Create a project

Copy link

To get started, open Xcode and create a new project. The Live SDK for iOS only supports Swift.


Step 2 Install the Live SDK

Copy link

You can install the Live SDK through either Swift Package Manager or CocoaPods. When you install the Live SDK, Sendbird Chat SDK will be installed as a dependency. The names of the framework and the main class in the Live SDK are SendbirdLiveSDK and SendbirdLive, respectively.

Note: If you have already been using Sendbird Chat or want to know the minimum version of the Chat SDK to use the Live SDK, you can check the information in Sendbird Live SDK repository.

Swift Packages

Copy link
  1. Go to your Swift Package Manager's File tab and select Swift Packages. Then choose Add package dependency....

  2. Add SendbirdLiveSDK into your Package Repository as below:

https://github.com/sendbird/sendbird-live-sdk-ios
  1. To add the package, select Version Rules, enter Up to Next Major, 1.0.0, and click Next.

CocoaPods

Copy link
  1. Add SendbirdLiveSDK into your Podfile in Xcode as below:
platform :ios, '11.0'
use_frameworks!

target YOUR_PROJECT_TARGET do
    pod 'SendbirdLiveSDK', '>= 1.0.0' // Add this line.
end
  1. Install the SendbirdLiveSDK framework through CocoaPods.
$ pod install
  1. Update the SendbirdLiveSDK framework through CocoaPods.
$ pod update

Step 3 Request permission to access camera and microphone

Copy link

Users need to grant the client app the permission to access camera and microphone to stream media. They also need to grant permission to access the photo library to send and download images and videos.

<key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) would like access to your photo library</string>
<key>NSCameraUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to access your camera</string>
<key>NSMicrophoneUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to access your microphone</string>
<key>NSPhotoLibraryAddUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to save photos to your photo library</string>

Step 4 Initialize the SendbirdLiveSDK instance

Copy link

To integrate the Live SDK in the client app, you need to initialize it first. But, prior to initializing the Live SDK, you must initialize Sendbird Chat SDK first. Refer to the following documentation to understand how to initialize Sendbird Chat SDK.

After initializing Sendbird Chat SDK, initialize the SendbirdLive instance using the SendbirdLive.initialize() method. Initialization requires your Sendbird application's Application ID, which can be found on the Sendbird Dashboard.

let initParams = SendbirdLive.InitParams(applicationId: APP_ID)
SendbirdLive.initialize(params: initParams)

Note: The SendbirdLive.initialize(applicationId:) method must be called across the client app at least once. It is recommended to initialize the Live SDK through the application:didFinishLaunchingWithOptions: method of the AppDelegate instance.

Step 5 Authenticate a user

Copy link

To start or enter a live streaming, you need to authenticate a user with the Sendbird server using their user ID through the authenticate() method.

SendbirdLive.authenticate(userId: USER_ID, accessToken: ACCESS_TOKEN) { user, error in
   guard let user = user, error == nil else { return }
   // The user has been authenticated successfully and is connected to Sendbird server.
}

Authenticating a user with the Live SDK will also authenticate the user in the Chat SDK if you haven't authenticated the user in the Chat SDK yet. After authenticating the user, you can start broadcast or watch live events.

Step 6 Create a live event

Copy link

To start a live event, you need to create one first. A live event can be created using the SendbirdLive.createLiveEvent() method, and you can configure information about the live event through the LiveEvent.CreateParams instance.

var params = LiveEvent.CreateParams()
params.title = TITLE
params.coverUrl = COVER_URL
params.customItems = CUSTOM_ITEMS
params.reactionKeys = REACTION_KEYS

SendbirdLive.createLiveEvent(config: params) { result in
    guard result.isSuccess else { return } // Handle Error

    // Live Event has been created.
}

Step 7 Start your first live

Copy link

When a live event is created, you can choose to enter as a host or a participant.

let mediaOptions = MediaOptions(turnVideoOn: true, turnAudioOn: true)
liveEvent.enterAsHost(options: mediaOptions) { result in
    guard result.isSuccess else { return } // Handle error

    // The user has entered as a host.
}

If you've entered as a host, you can start the live event by making the following call.

liveEvent.startEvent(mediaOptions: nil) { error in
    guard error == nil else { return } // Handle error

    // The live event has started. Participants can now view the host's video.
}

Step 8 Watch your first live

Copy link

When a host and participants enter the live event, you can stream the first live event for participants to watch with Sendbird Live. The host and participants also can actively engage in the live event by chatting with each other.

SendbirdLive.getLiveEvent(id: LIVE_EVENT_ID) { result in
    guard let liveEvent = result.success else { return } // Handle error

    liveEvent.enter { error in
        guard error == nil else { return } // Handle error

        // User has entered the live event.
    }
}