Swati Rout
Swati Rout

Reputation: 29

How to add survey monkey ios sdk inside my ios application?

How to integrate Surveymonkey ios SDK inside my iOS App?

ViewController.h I have tried following code in my project;

#import <UIKit/UIKit.h>
#import <SurveyMonkeyiOSSDK/SurveyMonkeyiOSSDK.h>
@interface ViewController : UIViewController
@property (nonatomic, strong) SMFeedbackViewController * feedbackController;

@end
ViewController.m

#import "ViewController.h"
//static NSString *SAMPLE_SURVEY_HASH=@"e7bvbydjgchg6vyr2qyrzxkq";

 //#define SAMPLE_SURVEY_HASH  @"43w3IKqgkvJCvRLvKo8BXt_2FrXe_2BVheRgqp5w2R5TC2c_3D"
#define FEEDBACK_QUESTION_ID @"813797519"
#define FEEDBACK_FIVE_STARS_ROW_ID @"9082377273"
#define FEEDBACK_FOUR_STARS_ROW_ID @"9082377274"
#define SAMPLE_APP @"survey_sample"
#define SURVEY_HASH @"LBQK27G"
#define APP_ID @"DH9K6DY"
@interface ViewController () <SMFeedbackDelegate, UIAlertViewDelegate>

@property (weak, nonatomic) IBOutlet UIButton *takeSurveyButton;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;


//#define SAMPLE_SURVEY_HASH e7bvbydjgchg6vyr2qyrzxkq;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _feedbackController = [[SMFeedbackViewController alloc] initWithSurvey:SURVEY_HASH];
    _feedbackController.delegate = self;
    [_feedbackController scheduleInterceptFromViewController:self withAppTitle:@"survey_sample"];
 [_feedbackController presentFromViewController:self animated:YES completion:nil];
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)didTapTakeSurvey:(id)sender {

}

- (void)respondentDidEndSurvey:(SMRespondent *)respondent error:(NSError *) error {

    if (respondent != nil) {
        NSLog(@"val is %@",respondent);
        SMQuestionResponse * questionResponse = respondent.questionResponses[0];
        NSLog(@"val new  is %@",questionResponse.questionID);
        NSString * questionID = questionResponse.questionID;
        if ([questionID isEqualToString:FEEDBACK_QUESTION_ID]) {
            SMAnswerResponse * answerResponse = questionResponse.answers[0];
            NSString * rowID = answerResponse.rowID;
            if ([rowID isEqualToString:FEEDBACK_FIVE_STARS_ROW_ID] || [rowID isEqualToString:FEEDBACK_FOUR_STARS_ROW_ID]) {
                [self showAlertWithBody:NSLocalizedString(@"Please rate us in the app store!", @"") hasRateButton:YES];
            }
            else {
                [self showAlertWithBody:NSLocalizedString(@"We'll address the issues you encountered as quickly as possible!", @"") hasRateButton:NO];
            }
        }
    }
   else {
       NSLog(@"error is %@",error);
   }

}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
    }
    else if(buttonIndex == 1)
    {
        NSString *appStoreURL = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?mt=8", APP_ID];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStoreURL]];
    }
}

- (void) showAlertWithBody:(NSString *)body hasRateButton:(BOOL)hasRateButton {
    UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"Thanks for your feedback!", @"Heading for feedback prompt")
                                                     message:body
                                                    delegate:self
                                           cancelButtonTitle: NSLocalizedString(@"Cancel", @"Title of cancel button on app store rating prompt")
                                           otherButtonTitles: nil];
    if (hasRateButton) {
        [alert addButtonWithTitle:NSLocalizedString(@"Rate Us", @"Title of rate us button on app store rating prompt")];
    }
    [alert show];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Still I am not able to customize the code provided in GitHub. Please help if you have already implemented it in your iOS app.

Upvotes: 0

Views: 652

Answers (1)

bleiken
bleiken

Reputation: 143

Apologies Swati & Horizon_Net -- the SurveyMonkey iOS SDK has not been officially released yet -- it's currently only available in a private beta. I'm the developer for the Android and iOS SDKs and would love to get your feedback. So, if you'd like to get in the beta, fill out this form.

We'll update this thread when the SDK has been publicly released, thanks for your patience.

Upvotes: 1

Related Questions