Live iOS v1
Live iOS
Live
iOS
Home
/
Live
/
iOS
/
SDK

Manage custom items

With custom items for live events, you can store additional information as key-value pairs to the LiveEvent object. Custom key-value items are saved as a [String: String] dictionary and can be updated or deleted by the users specified in userIdsForHost. Information related to the live event can be added as custom items for better user experience.


Add

When creating a live event, users can add custom items by adding it to LiveEvent.CreateParams as [String: String] dictionary type. By default, customItems is an empty dictionary.

let params = LiveEvent.CreateParams()
params.customItems = customItems

Update and delete

Custom items can be updated or deleted when a live event is in the ongoing state. If a new custom item has the same key as the existing custom item, the new item updates the value of the existing item. If the new item has a new key, it's added to the list of existing custom items. You can update those custom items by calling liveEvent.updateCustomItems(customItems:completionHandler:).

liveEvent.updateCustomItems(customItems: newDictionary) { customItems, updatedKeys, error in
    guard error == nil else { return }
    // Custom items successfully updated with newDictionary.
    // `updatedKeys` contains custom item keys that have been updated.
}

You can delete custom items by calling liveEvent.deleteCustomItems(customItemKeys:completionHandler:) with the list of keys that you want to delete from the list of custom items. If you want to delete all custom items in a live event, you can call liveEvent.deleteAllCustomItems(completionHandler:).

liveEvent.deleteCustomItems(customItemKeys: deleteKeys) { customItems, deletedKeys, error in
    guard error == nil else { return }
    // Custom items successfully deleted.
    // `deletedKeys` contains custom item keys that have been deleted.
}

liveEvent.deleteAllCustomItems { error in
    guard error == nil else { return }
    // All custom items have been deleted from the live event.
}

Receive events

A participant in a live event can receive events from the Sendbird server when the custom item is modified. The events are delivered to LiveEventDelegate only when the live event is in the ongoing state. Implement didUpdateCustomItems(updatedKeys:) and didDeleteCustomItems(deletedKeys:) from LiveEventDelegate to receive events in the live event. Each event contains the list of keys of the changed custom items, such as updatedKeys or deletedKeys.

class MyClass: LiveEventDelegate {
    func didUpdateCustomItems(_ liveEvent: LiveEvent, customItems: [String : String], updatedKeys: [String]) {
        // Custom items have been updated.
    }

    func didDeleteCustomItems(_ liveEvent: LiveEvent, customItems: [String : String], deletedKeys: [String]) {
        // Custom items have been deleted.
    }
}