Show a survey in your iOS app
Open a survey in a native iOS sheet when a customer reaches a particular moment in your app. For example, a feedback button on an order confirmation screen can ask what influenced the purchase. You choose when the sheet opens.
Try the example in Xcode
- Publish the survey in Shopoll. If it should appear only in your app, leave automatic website selection off.
- In Installation → iOS SDK, choose your survey and download the SDK. The Swift setup code shows the app origin, public workspace ID and survey ID.
- Unzip the download and open
ios/Example/SurveyExample.xcodeproj. Choose an iPhone simulator and run SurveyExample. - Enter the origin and both IDs, then tap Preview survey. You can answer questions and dismiss the sheet. The workspace records these answers under Results → Explore → Preview responses. They use no response allowance.
Add Shopoll to your app
In Xcode, choose File → Add Package Dependencies → Add Local. Select the unzipped folder containing Package.swift and add the Shopoll library to your app target. The package targets iOS 15 and uses Swift tools 5.7 or later.
Keep the client on your app or screen model and call it on the main thread. Start with the code from Installation. Set preview: false when you want live responses.
// In a SwiftUI button action
shopoll.trigger(survey: surveyID)
// From a visible UIKit view controller
shopoll.trigger(survey: surveyID, from: self)
Resume a response
Shopoll saves live answers as the customer advances. Reopening a partially answered survey restores its answers on the original published revision. Once a completed response is saved, triggering the same survey again keeps the sheet closed. If a customer skips every optional question, no response is saved and the survey can open again. Preview opens a fresh copy of the current published revision.
Before a customer signs in, their survey progress stays associated with that device. When your customer signs in, call identify. To share progress across their devices, provide the same private random UUID from your authenticated backend. Store a separate key for each customer. Keep this key out of URLs, analytics and client logs.
shopoll.identify(id: customerID, metadata: ["name": displayName], resumeKey: privateResumeKey)
shopoll.setMetadata(["cohort": "returning"])
An ID alone scopes progress to the current device. Call shopoll.logout() when the customer signs out. For identified responses, Shopoll adds the platform, SDK version, app version and mobile source alongside your metadata. An anonymous survey omits the participant and your custom metadata.
React to the sheet
Use onLoad when the sheet becomes visible. onComplete receives the answers when the customer finishes. onClose receives the answers collected by the time the sheet closes, including a partial response. Each answer contains the question ID, label and display value. Use onError for loading and presentation errors.
shopoll.onComplete = { answers in
showThankYou(answerCount: answers.count)
}
shopoll.onError = { error in
showFeedbackError(error.localizedDescription)
}
To troubleshoot, check that the survey is published in the workspace whose ID you supplied, the device can reach the app origin, and the presenting screen is visible. Installation → Check again shows the latest live iOS visit.