From 91f93baeec534b5416be95b3573b04619da7f364 Mon Sep 17 00:00:00 2001 From: Hitesh Jain Date: Wed, 8 Mar 2023 17:01:59 +0530 Subject: [PATCH] Update Readme --- README.md | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/README.md b/README.md index dc82b8d..30c0cbb 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,11 @@ Then, run the following command: $ pod install ``` +**OR** + +##### Install the SDK with SPM +Instructions for [Swift Package Manager](https://swift.org/package-manager/) support can be found at [SwiftPackageManager.md](SwiftPackageManager.MD). + #### Step 2: Set up your SDK Collector You must create your survey and set up your SDK Collector in [www.surveymonkey.com](https://www.surveymonkey.com). @@ -124,6 +129,78 @@ To present a survey for the user to take, call: [_feedbackController presentFromViewController:self animated:YES completion:nil]; ``` +##### Please follow below steps for Swift implementation : + +```swift +import UIKit +import SurveyMonkeyiOSSDK + +class SomeViewController: UIViewController, SMFeedbackDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + //Add your survey hash here + guard let sm = SMFeedbackViewController.init(survey: "surveyHash") else { return } + sm.present(from: self, animated: true, completion: nil) + sm.delegate = self + } + + //Called when The survey respondent data is returned as an SMResponse + func respondentDidEndSurvey(_ respondent: SMRespondent!, error: Error!) { + if respondent != nil { //... } + } +} +``` + +##### Please follow below steps for SwiftUI implementation : +`UIViewControllerRepresentable` instance is used to create and manage a UIViewController object in your SwiftUI interface. + +```swift +import SwiftUI +import UIKit +import SurveyMonkeyiOSSDK + +struct SMView: UIViewControllerRepresentable { + func makeUIViewController(context: Context) -> SMViewController { + let vc = SMViewController() + return vc + } + func updateUIViewController(_ uiViewController: SMViewController, context: Context) { + } + typealias UIViewControllerType = SMViewController +} + +class SMViewController: UIViewController, SMFeedbackDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + //Add your survey hash here + guard let sm = SMFeedbackViewController.init(survey: "surveyHash") else { return } + sm.present(from: self, animated: true, completion: nil) + sm.delegate = self + } + + //Called when The survey respondent data is returned as an SMResponse + func respondentDidEndSurvey(_ respondent: SMRespondent!, error: Error!) { + if respondent != nil { //... } + } +} + + //Called from SWIFTUI view to load the form +struct ContentView: View { + @State private var showingSMForm:Bool = false + + var body: some View { + Button("Take Survey", action: { + self.showingSMForm = !self.showingSMForm + }) + if(showingSMForm) { + SMView() + } + } +} +``` + #### Issues and Bugs To report issues with the SDK collector, please contact us at api-support@surveymonkey.com.