Live SDKs iOS v1
Live SDKs iOS
Live SDKs
Version 1

Add reactions to a live event

Copy link

When participating in a live event, adding the reactions function can help users be more engaged with the event and provide feedback from each other. This function is similar to the reactions you might have seen in Instagram or YouTube live streams.

Add reaction keys

Copy link

To use reactions, the host first needs to specify the types of reactions they want to allow during the live event. These reactions are represented by reactionKeys which are labels for reactions like a heart or a thumbs up.

Refer to the following lines of code to add your reaction keys to the live event.

struct LiveEvent.CreateParams {
    var reactionKeys: [String]

let reactionKeys = ["heart", "thumbs_up", "laugh"]
let params = LiveEvent.CreateParams(reactionKeys: reactionKeys)
SendbirdLive.createLiveEvent(config: params) { result in
  // Live event created with `result`.

Send reactions to others

Copy link

During the live event, the host and participants can use reaction keys to express their feelings.

The increaseReactionCount method is called to increase the count of a particular reaction key. For example, to send a heart, call the method with "heart" as the parameter.

liveEvent.increaseReactionCount("heart") { reactions, error in
    guard let reactions = reactions, error == nil else {
        return // Error occurred while increasing the reaction count.

    // Reaction count successfully increased.

The increaseReactionCount method internally uses the openChannel object to show the increase of the meta counter for the specified reaction key.

Show reaction counts

Copy link

Users in the live event will receive update on the reaction counts as it updates through the LiveEventListener interface. You can apply special effects to show reaction counts such as animated hearts flying across the screen.

protocol LiveEventDelegate {
    func didReactionCountUpdate(_ liveEvent: LiveEvent, key: String, count: Int)

class MyClass : LiveEventDelegate {
    func didReactionCountUpdate(_ liveEvent: LiveEvent, key: String, count: Int) {
        // update the UI to reflect the new count for the specified reaction key