我有一个基于swift的项目,需要使用Survey Monkey SDK。我曾尝试将SDK作为外部框架手动导入一次,并且还在另一次通过pod依赖项安装它。但是我无法从我的swift类访问SDK作为可导入模块。所以我创建了一个objc-swift桥接头文件,并可以访问框架的类。我可以展示调查。但是,当用户完成填写调查时,不会触发任何事件。我已经实现了- (void)respondentDidEndSurvey:(SMRespondent *)respondent error:(NSError *) error;
但是块似乎没有被执行。这是班级:
#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
我创建了一个基于objc的项目并尝试了相同的功能,它按预期工作。因此,在基于swift的项目中,如何在调查结束时得到受访者的回答?
答案 0 :(得分:1)
我注意到@interface SurveyViewController
类扩展了NSObject
。所以我把它改成了UIViewController
的子类,在其上面显示了调查猴子视图。因此,在触发delegate
方法之前,不会释放父视图。 Thanx @bleiken提示。