Swift UI App
Below are the various processes involved in setting up SpotChecks in iOS
Installation
-
Open XCode and click on "File" menu
-
Click on "Add Package Dependency"
-
Enter the package URL - https://github.com/surveysparrow/surveysparrow-ios-sdk.git
-
Select the version of SDK and Add to App Targets.
-
Then, click on Add Package to add the SurveySparrowSdk package to your iOS project.
The SurveySparrowSdk package can also be added by navigating to your target's General panel -> In the “Frameworks, Libraries, and Embedded Content” section, click on the + button -> select "Add Other "-> choose "Add Package Dependency" -> Enter the above package URL -> Click on Add Package.
Permissions (Info.plist)
Merge these keys into your app target’s Info settings or Info.plist. Replace REASON with text shown in the system permission prompt.
General networking does not require extra Info.plist entries. Add usage descriptions only for survey features you ship (camera, voice, or photo library).
Optional — camera (photo capture)
<key>NSCameraUsageDescription</key>
<string>REASON</string>
Optional — voice transcription
<key>NSMicrophoneUsageDescription</key>
<string>REASON</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>REASON</string>
Optional — photo library (pick existing photos)
<key>NSPhotoLibraryUsageDescription</key>
<string>REASON</string>
Optional — photo library (save images)
<key>NSPhotoLibraryAddUsageDescription</key>
<string>REASON</string>
Initialization
Import the SurveySparrowSdk and initialize a variable named spotCheck.
import SurveySparrowSdk
Anonymous users
If you wish not to keep track of users' data, you can follow the below syntax for initialization.
var spotCheck = Spotcheck (
domainName: "<your_domain>",
targetToken: "<target_token>",
userDetails: [:],
variables: [
"sparrowLang": "ta" // Eg: ta, en
],
customProperties: [:]
)
Known Users
If you wish to keep track of user's data and perform conditional Survey triggers, you can follow the below syntax for initialization.
var spotCheck = Spotcheck (
domainName: "<your_domain>",
targetToken: "<target_token>",
userDetails: [
email: 'example@email.com',
firstName: '<your-first-name>',
lastName: '<your-last-name>',
mobile: '<user_mobile>',
uuid: '<uuid_value>' // Optional
],
variables: [
"sparrowLang": "ta", // Eg: ta, en
<api_identifier_of_variable>: '<variable_value>',
],
customProperties: [
<custom_property_name>:'<value>'
]
)
Add the spotCheck in the ZStack of the topmost parent. The spotCheck.navControllerFinder should be applied as a background modifier to the topmost element inside NavigationView to support spotCheck buttons. It is encouraged to add this on the topmost element inside the NavigationView.
var body: some View {
ZStack {
NavigationView {
<your-topmost-element> {
<your-app-code>
}
.background(spotCheck.navControllerFinder) // Navigation listener for SpotChecks buttons
}.navigationViewStyle(StackNavigationViewStyle()) // Must Keep stack-style navigation
spotCheck //Integrate at the root of the app
}
}
Screen Track
It provides the ability to keep track of screens the users are visiting and to enable the survey trigger on that screen.
Syntax:
.onAppear {
spotCheck.TrackScreen(
screen: "<your-screen-name>" //eg. PaymentScreen
)
}
Example:
If a survey needs to be triggered on the payment page, the name of the ScreenName should be specified in the TrackScreen function.
spotCheck.TrackScreen(
screen: "PaymentScreen"
)
Event Track
It provides the ability to keep track of events which when triggered, will enable the survey to be popped.
Syntax:
spotCheck.TrackEvent(
onScreen: "<your-screen-name>" //eg. ScreenName,
event: [
"<your-events-or-functions>":[:] //eg. "onButtonPressed": [:]
]
)
Example:
If a survey needs to be triggered when the user completes a payment, then the TrackEvent function should be called with the respective ScreenName and optional custom properties.
spotCheck.TrackEvent(
onScreen: "paymentScreen",
event: [
"paymentComplete": [
"email" : "[email protected]",
"paymentStatus" : true
]
]
)
Callbacks (Optional)
Callbacks are used to listen to events that are part of the SpotChecks. All callback functions are optional — you can implement only the ones you need. The available callbacks include:
-
Survey Response - triggers when the user submits a response.
-
Survey Loaded - triggers when the SpotChecks is loaded on the user's page.
-
Survey Close - triggers when the SpotChecks is closed by the user.
-
Partial Submission - triggers when the PartialSubmission is enabled and received.
Syntax:
// Step 1: Add callbacks to the SpotChecks Initialization
var spotCheck = Spotcheck(
//...
surveyDelegate: SsDelegate()
)
// Step 2: Listen to the SpotChecks events
class SsDelegate: UIViewController, SsSpotcheckDelegate {
func handleSurveyResponse(response: [String : AnyObject]) async {}
func handleSurveyLoaded(response: [String : AnyObject]) async {}
func handleCloseButtonTap() async {}
func handlePartialSubmission(response: [String : AnyObject]) async {}
}