Я подхожу к проблеме, когда у меня есть список вопросов json, где, когда пользователь заполняет общие вопросы, я показываю кнопку для отправки, и все, что я хочу сделать, - это сделать эту кнопку отправки, чтобы отправить мне json результаты на мою электронную почту. это возможно с моим кодом? Спасибо огромное! Кстати, я использую SurveyNative для создания опросов.
import UIKit
import SurveyNative
class MyViewController: SurveyViewController, SurveyAnswerDelegate, CustomConditionDelegate, ValidationFailedDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.setSurveyAnswerDelegate(self)
self.setCustomConditionDelegate(self)
self.setValidationFailedDelegate(self)
}
override func surveyJsonFile() -> String {
return "GeneralQuestions"
}
override func surveyTitle() -> String {
return "General Questions"
}
func question(for id: String, answer: Any) {
print("Question: \(id) has answer (maybe is complete): \(answer)")
if (surveyQuestions!.isQuestionFullyAnswered(id)) {
print("Question: \(id) is complete")
}
}
func isConditionMet(answers: [String: Any], extra: [String: Any]?) -> Bool {
let id = extra!["id"] as! String
if id == "check_age" {
if let birthYearStr = answers["birthyear"] as? String, let ageStr = answers["age"] as? String {
let birthYear = Int(birthYearStr)
let age = Int(ageStr)
let wiggleRoom = extra!["wiggle_room"] as? Int
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year], from: date)
let currentYear = components.year
return abs(birthYear! + age! - currentYear!) > wiggleRoom!
} else {
return false
}
} else {
Logger.log("Unknown custom condition check: \(id)")
return false
}
}
func validationFailed(message: String) {
let alert = UIAlertController(title: nil, message: message, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
Мой Json:
{
"questions": [
{
"id": "ice_cream",
"header": "Question 1",
"question": "Did you enjoy the discussion topic?",
"question_type": "single_select",
"options": [
"YES",
"NO",
"I DONT KNOW",
{
"title": "Other",
"type": "freeform"
}
]
},
{
"id": "perfect_day",
"header": "Question 2",
"question": "Did you enjoy the presenter? If yes, why?",
"question_type": "single_select",
"options": [
"YES",
"NO",
"I DONT KNOW",
{
"title": "Other",
"type": "freeform"
}
]
},
{
"id": "ice_cream",
"header": "Question 3",
"question": "Did you feel you engaged or connected to the topic discussed?",
"question_type": "single_select",
"options": [
"YES",
"NO",
{
"title": "Other",
"type": "freeform"
}
]
},
{
"id": "perfect_day",
"header": "Question 4",
"question": "Do you have any topics you would like to discuss?",
"question_type": "single_select",
"options": [
"YES",
"NO",
"I DONT KNOW",
]
},
{
"id": "felt_like_adult",
"header": "Question 5",
"question": "Do you feel we can change anything?",
"question_type": "single_select",
"options": [
"YES",
"NO",
"I DONT KNOW",
]
},
{
"id": "pets",
"header": "Question 6",
"question": "Do you prefer a specific presenter? If yes, why?",
"question_type": "single_select",
"options": [
"YES",
"NO",
"I DONT KNOW",
{
"title": "Other",
"type": "freeform"
}
]
},
],
"submit": {
"button_title": "Submit Answers",
"url": "https://www.example.com"
},
"auto_focus_text": true
}