Poll posts in an iOS app

How to build poll posts in an iOS app

Mark Worachote
Mark Worachote
Solutions Engineer
Aug 21, 2023

Interactive content like polls has become a significant engagement tool in the realm of social media. This tutorial will guide you through the process of creating your own poll type post for iOS using the Amity Social Cloud SDK. We will explore the steps to set up the poll structure, define the question and answers, and finally, integrate the poll into a post. By the end of this guide, you will be proficient in creating engaging poll posts for your iOS applications. Let’s get started!

Before we begin, ensure you have the following:
- The Amity SDK installed and set up in your iOS project.
- A valid `pollId` which is obtained after creating a poll.
- A `postRepository` instance to create a post.
- If you haven’t already registered for an Amity account, we recommend following our comprehensive step-by-step guide on how to create your new network.

Authentication and Login:

Before creating a poll, you need to initialize the Amity SDK and log in to your account. Here is how you can do it:

Step 1: Create a poll

The first step is to create a poll. We will set up the poll structure, define the question, set the time to close the poll, and define the answers. Here is how you can do it:

Step 2: Create a poll post

After creating a poll, the next step is to create a poll post. We will build the post structure, set the text, and include the pollId. Here is how you can do it:

- The `targetId` and `targetType` parameters in the `createPollPost` function are used to specify where the post will be created. If `targetId` is `nil` and `targetType` is `.user`, the post will be created on the current user’s feed.
- The `metadata` and `mentionees` parameters are optional and can be used to add additional information to the post.

Final Thoughts

Creating interactive content like polls is a fantastic way to engage your users. With the Amity Social Cloud SDK for iOS, you can easily create polls and integrate them into your posts. This tutorial has provided you with the steps and code snippets to create a poll and a poll post in your iOS application. Remember, the key to creating engaging content is to ask interesting questions and provide relevant options for your users to choose from. Keep exploring and keep creating!