iOS SDK
Getting Started
If you haven't already, please start with the Getting Started Guide below.
📄️ Getting Started
Developer Guide | Polls Platform
Installation
The first step is to install the Polls Platform iOS SDK. You can install the SDK via Swift Package Manager or CocoaPods.
If you'd like to use another method such as Carthage or a Static Library,
we are happy to support you. Please contact us at partner@pollsplatform.com
.
- SwiftPM
- CocoaPods
1. Add Package Dependency
In Xcode, select File
> Add Packages...
2. Specify the Repository
Copy and paste the following into the search/input box.
https://github.com/polls-platform/iOS-SDK.git
3. Specify Options
In the options for the PollsPlatform
package, we recommend setting the Dependency Rule
to Up to Next Major Version
, and enter the
current Polls Platform SDK version.
4. Select the Package Products
Select the PollsPlatform
product, then click Add Package
.
Create a Poll
Once you have installed the SDK, you're ready to create your first poll.
- Swift
// 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) if let response = PollsPlatform.createPoll(poll: poll) { // poll can be opened immediately in the user's browser UIApplication.shared.open(response.url, options: [:], completionHandler: nil) } else { // response will only be nil if you forgot to configure the SDK }
Setting up Poll Data
The following is a more complete example of setting up fields for a poll.
- Swift
// poll title let title = "Which one should we book?" // poll settings let settings = PollSettings(multipleVotes: true, postVoteAction: .shareVote) // poll options (choices) let options = [ PollOption.default(title: "This is the first option", subtitle: "Subtitles are displayed below the title", details: "Details are on the third line", imageUrl: URL(string: "https://example.com/1")!, url: URL(string: "https://example.com/images/1.png")!, resourceId: "1"), PollOption.default(title: "This is the second option", subtitle: "Subtitles are displayed below the title", details: "Details are on the third line", imageUrl: URL(string: "https://example.com/2")!, url: URL(string: "https://example.com/images/2.png")!, resourceId: "2") ] // all together let poll = Poll(ownerId: User.current.id, settings: settings, title: title, options: options)
Opening the Poll
Continue to the next section to learn about the various options for opening the Poll.