Skip to main content

Embedding the Poll in your Mobile App

Navigation is a core part of your app, so our SDK aims to be flexible and allows you to control the navigation.

You will want to consider the following when planning navigation:

  1. Opening the poll after creating it
  2. Navigation to the Details screen of a Poll Option
  3. Opening a poll from a deeplink (for voters)
  4. Closing/Dismissing the poll


The PollViewController handles all of the functionality of viewing and interacting the a poll. The view controller can be used to display the poll after creating it, or for displaying a poll when a user opens it or deep links into it.

In the example below, we are creating an instance of the view controller and presenting it.

  let pollViewController = PollViewController(pollUrl: pollUrl,                                              flow: .createPoll,                                              delegate: self)    present(pollViewController, animated: true, completion: nil)


The PollViewControllerDelegate can be used to receive callbacks about what is happening in the poll.

extension YourViewController: PollViewControllerDelegate {        func didPressViewDetails(option: PollOptionResponse) {        // navigate to the details screen for the option        let detailViewController = DetailViewController(resourceId: option.resourceId)        navigationController?.pushViewController(detailViewController, animated: true)    }        func didReceiveAnalyticsEvent(event: AnalyticsEvent) {        // forward analytics to your system (e.g. Google Analytics)        Analytics.track(event:, parameters: event.parameters)    }    }

Putting it all together

At this point we have learned how to:

  1. Configure the SDK
  2. Create a poll by mapping our data into the poll fields
  3. Render a poll using the PollViewController
  4. Handle navigating to the Details Screen of an Option

Let's see it all together below

  // configure Polls Platform SDK    let config = PollsPlatform.Config(apiKey: "YOUR API KEY",                                    domainConfig: .subdomain(subdomain: "YOUR SUBDOMAIN"),                                    environment: .production)    PollsPlatform.setConfig(config: config)    // create a poll    let poll = Poll(ownerId: ownerId,                  settings: settings,                  title: title,                  options: options)    let response = PollsPlatform.createPoll(poll: poll)!    let pollViewController = PollViewController(pollUrl: response.url,                                              flow: .createPoll,                                              delegate: self)    present(pollViewController, animated: true, completion: nil)    // deep link into a poll    func handleDeepLink(url: URL) {      if (url.path.starts(with: "/poll/")) {          // this is a poll url          let pollViewController = PollViewController(pollUrl: response.url,                                                      // note we use .openPoll here                                                      flow: .openPoll,                                                      delegate: self)                    present(pollViewController, animated: true, completion: nil)      }  }