diff --git a/README.md b/README.md index 30c0cbb..da63046 100644 --- a/README.md +++ b/README.md @@ -60,36 +60,59 @@ You must create your survey and set up your SDK Collector in [www.surveymonkey.c ### Step 3: Importing to XCode 1. In the project navigation sidebar, right-click on the **Frameworks** group and select **"Add files to [ProjectName]"** -2. Navigate to the **surveymonkey-ios-sdk** directory that is contained in your cloned version of the **surveymonkey-ios-sdk** and select the **SurveyMonkeyiOSSDK.framework** file +2. Navigate to the **surveymonkey-ios-sdk** directory that is contained in your cloned version of the **surveymonkey-ios-sdk** and select the **SurveyMonkeyiOSSDK.xcframework** file 3. Make sure that **"Copy items if necessary"** is checked and all targets that will use the SDK are selected ### Step 4: Integrate the SurveyMonkey SDK with your app 1. Import the SDK +###### ObjC: ```objc #import ``` +###### Swift: +```swift +import SurveyMonkeyiOSSDK +``` 2. Depending on your usage, add a property to your interface: +###### ObjC: ```objc @property (nonatomic, strong) SMFeedbackViewController * feedbackController; ``` +###### Swift: +```swift +var surveyController: SMFeedbackViewController! +``` 3. Initialize the SDK and set its delegate: +###### ObjC: ```objc _feedbackController = [[SMFeedbackViewController alloc] initWithSurvey:{SAMPLE_SURVEY_HASH}]; _feedbackController.delegate = self; ``` +###### Swift: +```swift +self.surveyController = SMFeedbackViewController(survey: {SAMPLE_SURVEY_HASH}) +self.surveyController.delegate = self +``` 4. If you have Advantage Plan or higher, and want to include custom variables with each survey response, create a flat NSDictionary* with your custom variables and use: +###### ObjC: ```objc _feedbackController = [[SMFeedbackViewController alloc] initWithSurvey:{SAMPLE_SURVEY_HASH} andCustomVariables:{SAMPLE_CUSTOM_VARIABLES_DICTIONARY}]; ``` +###### Swift: +```swift +self.surveyController = SMFeedbackViewController(survey: {SAMPLE_SURVEY_HASH}, andCustomVariables: {SAMPLE_CUSTOM_VARIABLES_DICTIONARY}) +self.surveyController.delegate = self +``` ##### Important consideration Usage of the respondent data returned by the SurveyMonkey Feedback SDK requires that you have a **Advantage** account or higher and that your class implement the SMFeedbackDelegate and the ```-respondentDidEndSurvey:error:``` method therein The survey respondent data is returned as an SMResponse. Here's an example: +###### ObjC: ```objc - (void)respondentDidEndSurvey:(SMRespondent *)respondent error:(NSError *) error { if (respondent != nil) { @@ -112,44 +135,39 @@ The survey respondent data is returned as an SMResponse. Here's an example: } ``` +###### Swift: +```swift +extension ViewController: SMFeedbackDelegate { + func respondentDidEndSurvey(_ respondent: SMRespondent!, _ error: Error!) { + // TODO + } +} +``` Look at the [Simple Survey](https://github.com/SurveyMonkey/surveymonkey-ios-sdk/tree/master/SimpleSurvey) sample project in our Github repo for a detailed example. ##### The Intercept Modal To kick off the SurveyMonkey Feedback SDK Intercept process, call the following from your main activity: +###### ObjC: ```objc [_feedbackController scheduleInterceptFromViewController:self withAppTitle:{SAMPLE_APP_NAME}]; ``` +###### Swift: +```swift +self.surveyController.scheduleIntercept(from: self, withAppTitle: {SAMPLE_APP_NAME}) +``` This will check to see if the user should be prompted to take your survey (i.e. if (timeSinceLastSurveyPrompt > maxTimeIntervalBetweenSurveyPrompts)). You can customize the copy of the prompts, as well as the time intervals. See our [documentation](http://surveymonkey.github.io/surveymonkey-ios-sdk/) for more information about specific features and classes. ##### Presenting a Survey to the User To present a survey for the user to take, call: +###### ObjC: ```objc [_feedbackController presentFromViewController:self animated:YES completion:nil]; ``` - -##### Please follow below steps for Swift implementation : - +###### Swift: ```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 { //... } - } -} +self.surveyController.present(from: self, animated: true, completion: nil) ``` ##### Please follow below steps for SwiftUI implementation :