Skip to main content
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

| Parameter | Type | Description | Limits | |-----------|------|-------------|---------| | question | String | Poll question text | Max 500 characters | | answers | Array | Available answer options | 2-10 options, max 200 chars each |
| Parameter | Type | Description | Limits | |-----------|------|-------------|---------| | answerType | Enum | Single or multiple choice | Single (default), Multiple | | timeToClosePoll | Number | Poll duration in seconds | Default: 30 days |
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.

Parameters

  • pollId (String): The unique identifier of the poll - answerIds (Array<String>): IDs of selected answer options
do {
    let result = try await pollRepository.votePoll(withId: "<poll-id>", answerIds: ["<answer-id>"])
} catch {
    // Handle error here
}

Unvote on Polls

Allows users to remove their vote from a poll at any time before the poll closes.

Parameters

  • pollId (String): The unique identifier of the poll - answerIds (Array<String>): IDs of selected answer options
do {
    let result = try await pollRepository.unvotePoll(withId: "<poll-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

  • Keep questions clear and concise (under 500 characters) - Provide 2-6 answer options for better user experience - Use descriptive answer text (avoid generic “Option 1”, “Option 2”) - Consider your audience when setting poll duration
  • Indicate poll expiration time clearly - Provide visual feedback when votes are submitted - Handle edge cases (poll closed, already voted) - Show real-time vote counts when appropriate
  • Check poll status before allowing votes - Validate user permissions for management actions - Provide clear error messages for failed operations - Implement retry logic for network failures
  • Cache poll results to reduce API calls - Implement efficient polling for live updates - Consider pagination for polls with many votes - Optimize for mobile network conditions

Next Steps