/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
Version 4

Create a poll

Copy link

The polls feature allows group channel members and operators to create and send a poll attached to text messages. A poll usually consists of a question and at least one poll option that users can vote on. The functionality provides an easier way to gather feedback from groups of all sizes, collect data from customers, and drive user engagement. You can configure various settings for your poll, including when the poll will close and whether to allow users to add poll options or vote on multiple poll options.


Prerequisite

Copy link

To use polls in your Sendbird application, you must activate the polls feature on Sendbird Dashboard. Go to Settings > Chat > Features and turn on Polls.

Limitations

Copy link

Refer to the following limitations when using polls.

  • Polls can't be sent in the form of following message types: file messages, admin messages, and scheduled text messages.

  • Data on polls isn't included in the result when exporting message data.

  • The table below shows the types of channels that support polls. See the channel types section to learn about the differences among various channel types.

Open channelGroup channelSupergroup channel

Polls

Supported, except ephemeral channels

Supported, except ephemeral channels

Supported, except ephemeral channels

Note: The maximum number of options that can be added to a poll differs depending on your Sendbird plan. For further information, contact our sales team.


PollCreateParams

Copy link

You can create a poll by creating and passing a PollCreateParams object as an argument to the parameter in the createPoll() method. If successful, a poll is created. However, the poll has to be linked to a user message to actually be a valid poll. You can do this by assigning the poll's pollId to UserMessageCreateParams.pollId.

let pollParams = PollCreateParams()
pollParams.title = "Poll title"
pollParams.optionTexts = ["A", "B", "C"]
main.createPoll(params: pollParams) { poll, error in
    // A poll has been successfully created.
    // The poll needs to be sent as a user message.
}

List of parameters

Copy link
Parameter nameTypeDescription

title

string

Specifies the title of a poll.

optionTexts

Array of strings

Specifies the texts of possible options for which a user can vote on. Note that this property is only valid when creating a poll, but is ignored when updating a poll.

data

PollData

Specifies an additional data to accompany the poll. A use case might be to provide explanations for incorrect quiz answers.

isAnonymous

Bool

Determines whether to make votes anonymous. (Default: false)

allowUserSuggestion

Bool

Determines whether to allow users to make suggestions. (Default: false)

allowMultipleVotes

Bool

Determines whether to allow users to vote on more than one poll options. (Default: false)

closeAt

Int64

Specifies the time when a poll has closed or will close in Unix seconds. If the value of this property is -1, the poll status remains open meaning that the poll will never close.

PollHandler

Copy link

Through PollHandler, the Sendbird server always notifies whether your poll option has been successfully added.

public typealias PollHandler = (_ poll: Poll?, _ error: SBError?) -> Void