Note: Polls are currently supported within posts only. Standalone polls will be available in future SDK versions.

Key Features

Flexible Answer Types

Support for single or multiple choice voting patterns

Time-Limited Voting

Set automatic poll expiration with customizable durations

Moderation Controls

Owner-only management capabilities for poll lifecycle

Create a Poll

Create engaging polls with customizable settings and up to 10 answer options.
Design polls with clear, concise questions and meaningful answer options to maximize user engagement and response quality.

Configuration Options

func createPollExample() async {
    // Setup your poll structure
    let builder = AmityPollCreateOptions()
    builder.setQuestion("What is your favourite song?")
    // Time in milliseconds.
    builder.setTimeToClosePoll(60 * 60 * 1000)
    builder.setAnswerType(.single)
    let answers = ["My gift of silence", "Hope Leaves", "Lazarus"]
    for item in answers {
        builder.setAnswer(item)
    }
    // Create a poll from builder
    do {
        let pollId = try await pollRepository.createPoll(builder)
    } catch {
        // Handle error here
    }
}

Vote on Polls

Enable users to participate in polls with single or multiple choice voting.
Important: Votes are permanent and cannot be changed or revoked once submitted.

Parameters

do {
    let result = try await pollRepository.votePoll(withId: "<poll-id>", answerIds: ["<answer-id>"])
} catch {
    // Handle error here
}

Close Polls

Poll owners and administrators can manually close polls before their scheduled end time.
Permissions: Only poll creators and administrators can close polls.
do {
   let result = try await pollRepository.closePoll(withId: "<poll-id>")
} catch {
    // Handle error here
}

Delete Polls

Permanently remove polls from the system. This action cannot be undone.
Destructive Action: Poll deletion is permanent and removes all associated votes and data.
do {
   let result = try await pollRepository.deletePoll(withId: "<poll-id>")
} catch {
    // Handle error here
}

Best Practices

Next Steps