hassicho
hassicho

Reputation: 99

survey monkey iOS SDK

I have a swift based project and need to work with Survey Monkey SDK. I have tried to import the SDK manually as an external frameworks one time and also installed it through pod dependency the other time. However I could not access the SDK as importable module from my swift classes. So I have created an objc-swift bridging header file and get access to the framework's classes. I can display a survey. But no event is triggered when the user finishes filling out the survey. I have implemented - (void)respondentDidEndSurvey:(SMRespondent *)respondent error:(NSError *) error; But the block does not seem to be executed. Here is the class:

#import <Foundation/Foundation.h>
#import <SurveyMonkeyiOSSDK/SurveyMonkeyiOSSDK.h>
#import "SurveyViewController.h"
#import "ABC-Swift.h"

#define SURVEY_HASH @"SSSSSSS"

@interface SurveyViewController () <SMFeedbackDelegate>
@property (nonatomic, strong) SMFeedbackViewController * feedbackController;

@end

@implementation SurveyViewController

- (NSArray*)getSurveyResponse {

  return [NSArray new];
}

- (void)displaySurvey: (UIViewController *)context {
   _feedbackController = [[SMFeedbackViewController alloc] 
  initWithSurvey:SURVEY_HASH];
  _feedbackController.delegate = self;
  [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
  [_feedbackController scheduleInterceptFromViewController:context withAppTitle:SAMPLE_APP];
  [_feedbackController presentFromViewController:context animated:YES completion:nil];
}

- (void)respondentDidEndSurvey:(SMRespondent *)respondent error:(NSError *) error {
if (respondent != nil) {
    if(respondent.completionStatus == SMCompletionStatusComplete){
        NSLog(@"User answered all questions");
        //logic goes here

    }
    SMQuestionResponse * questionResponse = respondent.questionResponses[0];

    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]) {

        }
        else {

        }
    }
}
else {

}

}



@end

I have created an objc based project and tried the same function, it worked as expected. So in swift based project how can I get respondent's answer when the survey ends?

Upvotes: 1

Views: 840

Answers (1)

hassicho
hassicho

Reputation: 99

I noticed that the @interface SurveyViewController class extends NSObject. So I changed it to a subclass of UIViewController on top of which the survey monkey view is presented. So the parent view will not be deallocated before the delegate method is triggered. Thanx @bleiken for the hint.

Upvotes: 1

Related Questions