> For the complete documentation index, see [llms.txt](https://docs.zigpoll.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zigpoll.com/installation/ios-sdk.md).

# iOS SDK

Show Zigpoll surveys inside your iOS app. The SDK presents surveys in a native bottom sheet — you decide exactly when a survey appears by triggering it from code.

{% hint style="info" %}
Prefer to start from working code? Clone the ready-to-run [example app](https://github.com/zigpoll/zigpoll-ios-example). SDK source: [zigpoll-ios](https://github.com/zigpoll/zigpoll-ios).
{% endhint %}

## Requirements

* iOS 15 or later
* Swift 5.7 or later

## Installation

### Swift Package Manager

In Xcode, go to **File → Add Package Dependencies** and enter:

```
https://github.com/zigpoll/zigpoll-ios
```

### CocoaPods

Add to your Podfile and run `pod install`:

```ruby
pod 'Zigpoll'
```

## Set up your survey

1. In the Zigpoll dashboard, create a survey.
2. Set the survey's delivery type to **API** (Delivery Settings → API). This tells Zigpoll the survey only appears when your app requests it.
3. Copy the survey ID from the survey's install section.

{% hint style="info" %}
Leave the survey's response setting on the default (once per participant). URL-dependent response settings are a web concept and are not supported on mobile.
{% endhint %}

## Configure the SDK

Call `configure` once, early in your app's lifecycle (e.g. in your `App` init or `AppDelegate`):

```swift
import Zigpoll

Zigpoll.configure(accountId: "YOUR_ACCOUNT_ID")
```

Your account ID is shown in the dashboard under **Installation**.

## Identify the user (recommended)

```swift
Zigpoll.identify(id: "user_123", metadata: [
    "email": "jane@example.com",
    "name": "Jane"
])
```

Identified users keep their survey state across sessions and devices — a completed survey stays completed if you trigger it again. Without `identify`, an anonymous device-persistent ID is used instead.

Call `Zigpoll.logout()` when the user signs out.

## Trigger a survey

```swift
Zigpoll.trigger(pollId: "SURVEY_ID", from: viewController)
```

The survey slides up in a native bottom sheet. The `from:` parameter is optional — by default the top-most view controller presents the sheet, which works well in SwiftUI apps:

```swift
Button("Give feedback") {
    Zigpoll.trigger(pollId: "SURVEY_ID")
}
```

Responses are recorded slide by slide, so partial responses are captured even if the user dismisses the sheet mid-survey.

## Metadata

Attach metadata to responses for segmentation, targeting, and personalization:

```swift
Zigpoll.setMetadata(["plan": "pro", "cohort": "2026-Q3"])
```

The SDK automatically includes `source=mobile-sdk`, `platform=ios`, the SDK version, and your app version, so you can filter mobile responses in the dashboard.

## Callbacks

```swift
Zigpoll.onLoad     = { print("survey visible") }
Zigpoll.onComplete = { responses in print("completed", responses) }
Zigpoll.onClose    = { responses in print("closed", responses) }
Zigpoll.onError    = { error in print("error", error) }
```

`onComplete` fires once when the respondent finishes the survey. `onClose` fires whenever the sheet is dismissed, with any responses collected so far.

## Development builds

```swift
Zigpoll.configure(accountId: "YOUR_ACCOUNT_ID", preview: true)
```

With `preview: true`, surveys open and behave normally but responses are not billed or counted in your analytics. Use this in debug/QA builds.

## Notes

* Call all SDK methods on the main thread.
* The SDK has zero third-party dependencies and only presents UI when you trigger a survey — there is no background activity.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zigpoll.com/installation/ios-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
